Regular expression to match all domain names except admin / www / mail

I am new to regex, but give me this, I need to find a match:

a.com
b.com
c.com
aa.com
admin.com
www.com
mail.com
vg.com

      

As a result, I found a regular expression for all domains except admin / www / mail.

I wrote this:

[a-zA-Z0-9]+.com

      

But how to exclude admin, mail, www

I've tried this:

^(www|mail|admin)[a-zA-Z0-9]+.com

      

But it doesn't work

+3


source to share


4 answers


try it

\w+(?<!admin|mail|www)\.com

      

Here are some tests http://www.rubular.com/r/frRl1ucR8J



Further reading on regular expressions: http://www.regular-expressions.info/tutorial.html

And the trick I used is called Negative LookBehind http://www.regular-expressions.info/lookaround.html

+1


source


Don't just rule out some things, but here is a link to help:

http://www.codinghorror.com/blog/2005/10/excluding-matches-with-regular-expressions.html



Can the replacement be replaced first? First you can find / replace to eliminate lines that match the things you want to skip, then use your regex.

0


source


You would do this to find a line that does not contain admin:

^((?!admin).)*$

      

I'm not sure how to do this for multiple lines ...

0


source


I use this somewhat similar to the answer already.

/^[A-Za-z0-9._'%+-]+@(\[(\d{1,3}\.){3}|(?!hotmail|gmail|yahoo|live|msn|outlook|comcast|verizon)(([a-zA-Z\d-]+\.)+))([a-zA-Z]{2,4}|\d{1,3})(\]?)$/i

      

0


source







All Articles