I need to write a regular expression that will match everything in the string unless it has a certain word in it. Taking this string for example:
http://12.34.567.890/sqlbuddy
The expression that matches everything is:
^.*$
…Which needs to be modified so that it will not match the string at all if it contains the word “sqlbuddy”. I thought that a negative lookahead would do it, but that’s not working for me.
For example, I tried this, which doesn’t work:
^(?!sqlbuddy).*$
How should I modify this?
The example doesn’t work because it assumes
sqlbuddyis in the beginning of the string. You need to change it to the following, so thatsqlbuddycan appear anywhere in the string:However, if you really just want to check if your string contains a given word, then maybe a
"http://12.34.567.890/sqlbuddy".contains("sqlbuddy")will suffice.