frosty frosty - 7 months ago 13
SQL Question

Selecting a sentence in mysql starting with a word, and NOT followed by another word

I'm trying to select a sentence in mysql starting with the word 'by' and NOT followed by the word 'the', but it's not working somehow. What am I doing wrong?

SELECT *
FROM `allData`
WHERE response REGEXP '^by ?!the'

Answer

mysql regex doesn't support positive or negative lookeaheads. alternatively you could do something like

response REGEXP  '^by ' and response not like 'by the%'