How to use REGEXP on the word boundary in MySQL 8.0.5+?

时间秒杀一切 提交于 2019-11-29 14:59:13

First, note that REGEXP_REPLACE can match strings partially, and you do not need .* before and after a search word.

The \ char should be escaped in order to define a literal backslash, since \ itself allows escaping characters for the MySQL engine. See this MySQL 8 documentation:

Note

Because MySQL uses the C escape syntax in strings (for example, \n to represent the newline character), you must double any \ that you use in your expr and pat arguments.

Thus, you need

REGEXP_LIKE("aaa abc ccc", "\\babc\\b")

Also word boundaries: [[:<:]] and [[:>:]]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!