Reputation: 6251
I have made this regex:
(?<=span class="ope">)?[a-z0-9]+?\.(pl|com|net\.pl|tk|org|org\.pl|eu)|$(?=<\/span>)$
It does match the strings like: example.pl
, example12.com
, something.eu
but it will also match the dontwantthis.com
.
My question is how to don't match a string in case if it contains the dontwantthis
string?
Upvotes: 0
Views: 212
Reputation: 53531
It seems that you are extracting content from span
elements using a regular expression. Now, despite all the reasons why this is not such a good idea...
... just keep the expression you have. Then, if you have a match, filter out the matched entries that should be rejected.
var $match = extractContentFromHtml($html); // use regex here, return false if no match
if ($match && validMatch($match)) {
// do something
}
where validMatch(string)
should check if the value exists in some array, for example.
Upvotes: 1
Reputation: 324620
You're probably following your regex with a loop to cycle through matches. In this case, it's probably easiest to just check for the presence of the dontwantthis
substring and continue
if it's there. Trying to implement it in regex is just asking for trouble.
Upvotes: 3