我为此苦苦挣扎。
在 MySQL 中,我想在一列中查询以两位数结尾的字符串。我不在乎前面还有什么,只要最后一个字符是前面至少有一个非数字的两位数
例如,这些字符串应该匹配:
"Nov. 12th, 60"
"34 Bar 56"
"Foo-BAR-01"
"33-44-55"
"-------88"
"99"
当我这样做时:
SELECT <string> REGEXP <pattern>
现在,<pattern>
位是我需要帮助的地方。
谢谢。
最佳答案
SELECT * FROM mytable WHERE mycolumn REGEXP "^.*[^0-9][0-9]{2}$";
正则解释:
^.*[^0-9][0-9]{2}$
Assert position at the beginning of the string «^»
Match any single character that is NOT a line break character «.*»
Between zero and unlimited times, as few or as many times as needed to find the longest match in combination with the other quantifiers or alternatives «*»
Match any single character that is NOT present in the list below and that is NOT a line break character «[^0-9]»
A character in the range between “0” and “9” «0-9»
Match a single character in the range between “0” and “9” «[0-9]{2}»
Exactly 2 times «{2}»
Assert position at the very end of the string «$»
关于mysql REGEXP匹配以2位数字结尾且仅以非数字开头的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30034103/