Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone found that REGEX "\b" doesn't work in MYSQL?

Tags:

regex

php

mysql

Has anyone found that REGEX "\b" doesn't work in MYSQL?

I have a nice piece of regex that matches well using regex engines

^(//)?w7\b

But when I use it as part of a MYSQL query

WHERE ( e.department REGEXP '^(//)?w7\b' )

it will not match. If I remove the \b component, the match works well but its not to the accuracy that I need with the \b (basicly I need to match the whole word W7 only)

Thank you!

like image 216
Mark Avatar asked Jun 19 '11 14:06

Mark


1 Answers

For MySQL versions prior to MySQL 8.0.4, the REGEXP (MySQL 5.6 ref) docs indicate that the start-of-word/end-of-word markers are:

[[:<:]], [[:>:]]

These markers stand for word boundaries. They match the beginning and end of words, respectively.

Try:

WHERE ( e.department REGEXP '^(//)?w7[[:>:]]' )

After 8.0.4, \b is used for word boundary instead.

like image 56
Mat Avatar answered Oct 14 '22 06:10

Mat