在过滤数据库中的条目时,我一直在研究 REGEXP。
我有一个列,其中的值用逗号分隔,如下所示:
id A 列
|---|------------------------|
| 1 | P:1,P:2,P:5,P:7 |
| 2 | P:6,P:8,P:10,P:11 |
| 3 | P:4,P:3,P1,P:0 |
| 4 | P:2,P:1 |
|---|------------------------|
假设我想要包含值 P:1 的行,我如何设计一个 REGEXP 的形式:
SELECT * FROM `table` WHERE `col A` REGEXP '?'
以便我得到第 1、3 和 4 行?我以前的方法是简单地使用:
SELECT * FROM `table` WHERE `col A` LIKE 'P:1'
然而,这自然也会返回第 2 行,因为它在技术上包含 P:1...
任何帮助将不胜感激,我认为这个问题对于正则表达式专家来说相当简单!
干杯,
Andreas
最佳答案
您需要阅读 word boundaries .
[[:<:]], [[:>:]]
These markers stand for word boundaries. They match the beginning and end of words, respectively. A word is a sequence of word characters that is not preceded by or followed by word characters. A word character is an alphanumeric character in the alnum class or an underscore (_).
关于mySQL REGEXP 逗号之间的匹配值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13370263/