在 MySQL (8.0.5+) 中,使用 ICU-REGEXP 对字边界执行搜索不起作用。 据我了解应该是a-la
$ mysql -e 'SELECT REGEXP_LIKE("aaa abc ccc", ".*\b+abc\b+.*")'
+---------------------------------------------+
| REGEXP_LIKE("aaa abc ccc", ".*\b+abc\b+.*") |
+---------------------------------------------+
| 0 |
+---------------------------------------------+
但是这个选项不起作用。
最佳答案
首先,请注意 REGEXP_REPLACE
可以部分匹配字符串,并且搜索词前后不需要 .*
。
应该对 \
字符进行转义,以便定义文字反斜杠,因为 \
本身允许 MySQL 引擎转义字符。看这个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.
因此,您需要
REGEXP_LIKE("aaa abc ccc", "\\babc\\b")
关于mysql - 如何将 REGEXP 与字边界等转义序列一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57020006/