In MySQL versions before 8.0, you cannot use a single regex for that since it is a POSIX based regex that does not support lookarounds.
With earlier versions of MySQL, you could use something like
LIKE '%66-155%en application%' AND NOT LIKE '%66-155%<p>%en application%'
If, instead of literal substrings, you have regex patterns, then it would look like
REGEXP '66-155.*en application' AND NOT REGEXP '66-155.*<p>.*en application'
In MySQL 8.x, with the ICU regex engine, you may use a lookaround based regex:
REGEXP '66-155(?:(?!<p>).)*?en application'
The (?:(?!<p>).)*?
is a tempered greedy token that matches any char (other than a line break char, to match any char including line breaks, add (?s)
at the pattern start) with .
, as few repetitions as possible (due to *?
quantifier), that does not start a <p>
char sequence.
66-155
en application
' LIKE '%66-155%en application%' AND NOT LIKE '%66-155%%en application%'`. What is your MySQL version?
– Wiktor Stribiżew Sep 24 '18 at 21:28