mysql REGEXP匹配以2位数字结尾且仅以非数字开头的字符串

标签 mysql sql regex select

我为此苦苦挣扎。

在 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/

相关文章:

mysql - Zabbix 数据库升级失败。无法添加或更新子行: a foreign key constraint fails

mysql - SQL:带有复杂子查询的查询

sql - 使用要考虑的最大行数聚合 SQL 查询

SQL 日期时间到字符串格式

mysql - 如何使用 Outer Join 和 Group By 在查询中包含 NULL 值

php - 如何在查询字符串中进行精确模式匹配

mysql - 希伯来语的 sql 正则表达式

php - 具有公共(public)列的 MySQL 2 表仅在存在其他条件时才匹配

java - hibernate :如何选择表中的所有行

python - 以任意顺序查找符号条目