你好,我的sql查询需要一个正则表达式来匹配文本
"SIP/(10 NUMBERS)"
等于
"SIP/1234567890"
" SIP"是文字 和10个数字randoms 0-9
更新
最终文本为SIP / 0123456789-000001cc
其中
"SIP/" is text
"0123456789" Always 10 digits
"-" is character
"000001cc" is random alphanumeric
答案 0 :(得分:1)
您可以使用此正则表达式:
^SIP/[[:digit:]]{10}-
<强>示例:强>
mysql> select 'SIP/0123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-';
+----------------------------------------------------------+
| 'SIP/0123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-' |
+----------------------------------------------------------+
| 1 |
+----------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select 'SIP/123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-';
+----------------------------------------------------------+
| 'SIP/123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-' |
+----------------------------------------------------------+
| 0 |
+----------------------------------------------------------+
1 row in set (0.00 sec)
答案 1 :(得分:0)
使用\
转义/
以下RegEx的目标是SIP,然后是/
,然后是10位数的字符:
SIP\/\d{10}