Reputation: 5968
Trying to create a regular expression that excludes results of a substring is present.
Data Set:
http://www.cnn.com/test1
http://www.cnn.com/test3
http://www.cnn.com/test5
http://www.stackflow.com/test4
http://www.cnn.com/test3
http://www.cnn.com/test4
exclude:
Results:
http://www.cnn.com/test1
http://www.cnn.com/test5
http://www.cnn.com/test4
Upvotes: 1
Views: 41
Reputation: 28554
I'm guessing this would be fastest:
cnn\.com(?!\/test3)[a-zA-Z0-9-._~:?#@!$&'*+,;=`.\/\(\)\[\]]*
because you restrict the URL to allowed characters only.
Upvotes: 0
Reputation: 61063
If you want to avoid matching strings like http://www.cnn.com/test/test3
then you can use a negtive lookbehind at the end of the string
cnn\.com.*(?<!test3)$
Upvotes: 0