Word boundaries in MySQL regular expressions

Posted . Visible to the public.

In regular expressions you can use the zero-width pattern \b to match the beginning or end of a word:

note.title =~ /\bfoo\b/

Unfortunately \b is not available in MySQL. You can use [[:<:]] and [[:>:]] to match the beginning and end of a word instead:

SELECT * FROM notes WHERE title REGEXP "[[:<:]]foo[[:>:]]"

These markers are unique to MySQL and not available in Ruby regular expressions.

Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-12-19 21:59)