【发布时间】:2013-09-28 13:32:58
【问题描述】:
我正在尝试创建一个非常简单的搜索查询,它匹配任何搜索词,但匹配完整的单词,因此部分匹配是不可能的,例如
要查找的字符串是:
" (This is) my test string "
匹配的查询可能是:
"This is"
"(This is)"
"(This is"
"This is)"
"my test"
"string"
等等。但不是:
"This is my"
"(thi"
"my tes"
等等。因为这些只是部分匹配。 LIKE 在这里没有用,所以我正在尝试使用 REGEXP 和单词边界:
1. SELECT " (This is) my test string " REGEXP "(^|[[:<:]])this is([[:>:]]|$)"; -> 1
2. SELECT " (This is) my test string " REGEXP "(^|[[:<:]])\\(this is\\)([[:>:]]|$)"; -> 0
3. SELECT " This is my test string " REGEXP "(^|[[:<:]])this is([[:>:]]|$)"; -> 1
现在的问题是,为什么 pt.2 中的边界不覆盖空间,而它们似乎在 pt.3 中(去掉圆括号以显示差异)?我在这里错过了什么?
谢谢
【问题讨论】:
标签: mysql regex word word-boundaries