Skip to content
Home » MySQL » MySQL Word Boundaries

MySQL Word Boundaries

Word Boundaries

The usual word boundaries in regular expression is b, but MySQL takes POSIX-liked [[:<:]] and [[:>:]] as word boundaries. Now my question is the word boundaries include the beginning and end of a string? Let's do a simple experiment.

I would like to match the word 'great':

mysql> SELECT 'Great! We can go on NOW' REGEXP '[[:<:]]' 'great' '[[:>:]]' AS RESULT;
+--------+
| RESULT |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

The left boundary does match the beginning of the string.

Now, let's turn to see the right boundary:

mysql> SELECT 'Great! We can go on NOW' REGEXP '[[:<:]]' 'now' '[[:>:]]' AS RESULT;
+--------+
| RESULT |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

Now we know the word boundaries include the beginning and end of a string.

The above result also imply that the default matching behavior of REGEXP is case-insensitive, but ..., with some unknown exceptions: Is REGEXP (or RLIKE) Always Case Insensitive?.

Leave a Reply

Your email address will not be published. Required fields are marked *