3

Prior to MySQL 8.0.4, MySQL used the Henry Spencer implementation for REGEX and you could use this for word boundaries:

'[[:<:]]' and '[[:>:]]'

From 8.0.4 MySQL is using the ICU implementation and the word boundaries have changed to this:

'\\b'

I need to find out which REGEX implementation is used. Relying on MySQL version number might not be the best option as for example MariaDB has different version numbers.

I thought to check by querying MySQL and find out which implementation it's using like this:

"SELECT 1 FROM DUAL WHERE 'icu regex' REGEXP '\\bregex';"

This is working with MySQL 8.0.4 and previous versions. It will return 1 if the ICU implementation is used by the DB, 0 otherwise.

The opposite doesn't work instead as MySQL 8.0.4 throws an error:

"SELECT 1 FROM DUAL WHERE 'henry regex' REGEXP '[[:<:]]regex';"

Is there any better way to approach this?

MySQL reference about REGEX changes are here: https://dev.mysql.com/doc/refman/8.0/en/regexp.html#regexp-compatibility

freejack
  • 131
  • 2
  • (Note: Technically, there is only one backslash in front of `b`. But in some client contexts, 2 or perhaps 4 are needed.) – Rick James Jun 14 '19 at 07:38
  • There is one back slash but it needs to be escaped as mentioned in the doc, so you need two. Then you need to use more depending on the used language. The examples above were taken from my PHP code. I have removed two slashes to make the example clearer... – freejack Jun 14 '19 at 09:49

0 Answers0