How to write regular expression in MySQL select queries?

I tried this expression to /\b(word\w*)\b/icompare a wordwith a list of other words to find duplicates. I used preg_math_all()and it worked fine. I wanted to do the same, but this time to check the words retrieved from the mysql database. This is what I wrote

SELECT * FROM table WHERE word = /\b(word\w*)\b/i

it did not work.

+5
source share
2 answers

Your request should look like this:

SELECT * FROM table WHERE column REGEXP '/\b(word\w*)\b/i'
+7
source

MySQL regex syntax is different from PHP, you do not need delimiters at the beginning and at the end.

SELECT * FROM table WHERE word REGEXP '\b(word\w*)\b'

i , PHP, MySQL, , , .

+4

All Articles