Negate Word Groups? - Regular Expression (Regex)

348 views Asked by At

Its easy to get a regular expression that gets you ALL the "com/net/org"

Here it is:

^.+(com|org|net)$

BUT, I'm trying to find all domains that DON'T have a com/net/org

I can't seem to find a way to negate the word group com/net/org

Here are sample strings:

piquetraveldesign.com
rigall.com.au
hunt4me.co.uk
cialis-without-prescription.us
filipinocommunityseattle.org
mortgageplanningblog.com
mental-health-training.net
final-fantasy-xiv-gil.com
uoblife.com.sg
unashamedandassociates.biz
heaonlineshop.com

Any ideas?

2

There are 2 answers

2
hwnd On BEST ANSWER

You can use a Negative Lookahead assertion.

^(?!.*(?:com|net|org)$).+$
0
AudioBubble On

Since its fixed length you could use a negative lookbehind assertion.
If all the lines are in a single string, the multi-line mode must be set
so $ means end of line, instead of end of string.

 # .+(?<!\.(?:com|org|net))$

 .+ 
 (?<!
      \.
      (?: com | org | net )
 )
 $