[英]Check if a string contains number with more than 5 digits
我正在嘗試構建一個查詢來檢查字符串是否包含至少 5 個以上的連續數字。
詢問;
SELECT count(id) as gV FROM someTable WHERE ... title REGEXP '(\d{5,})' order by id limit 0,10
樣本數據
Some text here 123456 (MATCH)
S0m3 t3xt h3r3
Some text 123 here 345
98765 Some text here (MATCH)
Some12345Text Around (MATCH)
期望輸出
3 (Some text here 123456, 98765 Some text here, Some12345Text Around)
MySQL 查詢中的正則表達式是否有任何特定規則?
MySQL 的正則表達式引擎沒有實現\\d
"digit" 表達式,但您可以將其表示為字符類范圍,如[0-9]
或特殊字符類[[:digit:]]
。 您嘗試的形式支持花括號重復語法{5,}
。
手冊中描述了可用的正則表達式語法
因此,您可以使用以下任一形式:
title REGEXP '[0-9]{5,}'
title REGEXP '[[:digit:]]{5,}'
例子:
> SELECT '123' REGEXP '[[:digit:]]{5,}';
+--------------------------------+
| '123' REGEXP '[[:digit:]]{5,}' |
+--------------------------------+
| 0 |
+--------------------------------+
> SELECT '1X345' REGEXP '[0-9]{5,}';
+--------------------------------+
| '123' REGEXP '[0-9]{5,}' |
+--------------------------------+
| 0 |
+--------------------------------+
> SELECT '98765 Some text here' REGEXP '[[:digit:]]{5,}';
+-------------------------------------------------+
| '98765 Some text here' REGEXP '[[:digit:]]{5,}' |
+-------------------------------------------------+
| 1 |
+-------------------------------------------------+
> SELECT 'Some text here 123456' REGEXP '[0-9]{5,}';
+--------------------------------------------+
| 'Some text here 123456' REGEXP '[0-9]{5,}' |
+--------------------------------------------+
| 1 |
+--------------------------------------------+
1 row in set (0.00 sec)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.