0

I have a regular expression to match domains like so:

([a-z]+[0-9]{3,})+(\.net|\.com)

I would like to exclude the domain office365.com from the rule, so I do:

(?!office365\.com)([a-z]+[0-9]{3,})+(\.net|\.com)

But the problem is that the rule above matches the ffice365.com of the website, so eventually I need to write:

(?!office365\.com|ffice365\.com|fice365\.com|ice365\.com|ce365\.com|e365\.com)([a-z]+[0-9]{3,})+(\.net|\.com)

Is there a way to overcome this behaviour?

  • 3
    adding word-boundaries may help. For example right between the negative lookahead and your opening of the 1st capture group. `)\b(` – JvdV Aug 19 '21 at 12:32
  • How about instead of making a regex that gets bigger every time you want to exclude a website, just use code to see if "office365" exists in the string? – AaronJ Aug 19 '21 at 12:33

0 Answers0