Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dostogir's avatar

How to fix this quary for mysql 8

I get an error for MySQL version 8 to please how do I fix it this query does not support the MySQL 8 version.

->whereRaw('episodes.title REGEXP ?', ['[[:<:]]'.$search.'[[:>:]]'])

0 likes
1 reply
rodrigo.pedra's avatar
Level 56

According to

https://dev.mysql.com/doc/refman/8.0/en/regexp.html#regexp-compatibility

Versions before MySQL 8.0.4 used a different regular expression library (Henry Spencer regular expression library), whereas new versions use the International Components for Unicode (ICU).

The link above lists some differences between the implementations, and the one referring to your error is:

The Spencer library supports word-beginning and word-end boundary markers ([[:<:]] and [[:>:]] notation). ICU does not. For ICU, you can use \b to match word boundaries; double the backslash because MySQL interprets it as the escape character within strings.

So this should work:

->whereRaw('episodes.title REGEXP ?', ['\\b' . $search . '\\b'])
1 like

Please or to participate in this conversation.