I want to find matches for string example
but not www.example
. What is the regex I can use? I've tried the following but it doesn't work:
(?!www.\)example
I want to find matches for string example
but not www.example
. What is the regex I can use? I've tried the following but it doesn't work:
(?!www.\)example
If you just try to match a string that does start with example
but not with www.example
than it would be as easy as:
^example
Otherwise you can use a negative lookbehind:
(?<!\bwww\.)\bexample\b
The \b
in here is a word boundery, meaning that it matches it, as long as it is not part of a string. (In other words if it isn't followed by or following any A-Za-z characters, a number or an underscore.)
As mentioned by @CasimiretHippolyte this does still match strings like www.othersubdomain.example.com
.