Read more

Word boundaries in MySQL regular expressions

Henning Koch
December 19, 2010Software engineer at makandra GmbH

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

note.title =~ /\bfoo\b/
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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.

Posted by Henning Koch to makandra dev (2010-12-19 22:59)