Reputation: 16691
Im trying to perform a regex match in mysql to match a string when part of the string is not present. i.e
src="/images/(?legacy)
if the string src="/images/
is present but the string legacy
is not.
Any ideas ?
Upvotes: 0
Views: 601
Reputation: 610
I know this is not what you're asking, but MySQL regexes do not support negative lookahead and AFAIK mysql regexes dont use the index.
So i think you may be over thinking it, as the regex would be shorter in writing (if it could work, which it cant) but traditional LIKE is faster.
I suggest you simply use:
WHERE (
content LIKE '%src="/images/%'
AND
content NOT LIKE '%src="/images/legacy%'
)
Upvotes: 1
Reputation: 191749
MySQL regexen do not support negative lookaheads, so I think your best bet would be to use two or to use LIKE
string LIKE '%src="/images/%'
AND string NOT LIKE '%src="/images/legacy%'
Note that this query would be inefficient (as it would be using regexen).
Upvotes: 1