MySQL REGEXP不匹配 [英] mysql REGEXP not matching
问题描述
我有一个正则表达式,用于捕获字符串中的电话号码
I have a regular expression intended to catch phone numbers within a string
/[1,+ ().-][\s.-]\d{3}[\s.-]\d{3}[\s.-]\d{4}/
我尝试使用以下查询在MySql数据库中查询此正则表达式:
I try to query my MySql database for this regex using this query:
SELECT
*
FROM
`everything`.`instances_meta` AS m
WHERE
`meta.value` REGEXP "[1,+][\s.-]\d{3}[\s.-]\d{3}[\s.-]\d{4}"
我可以确认正则表达式本身,可以通过此处进行测试.查询时不进行任何匹配.某件事告诉我,我缺少某种表达来表示字符串中的任何地方".我会指定正则表达式引擎,但不确定MySql使用什么.
I can confirm the regex, itself, does what I want from testing it here but it does not pull any matches when queried. Something tells me I am missing some sort of expression to say "anywhere in the string". I would specify the regex engine but I am unsure of what MySql uses.
推荐答案
使用
"[1,+][[:blank:].-][0-9]{3}[[:blank:].-][0-9]{3}[[:blank:].-][0-9]{4}"
因为MySQL REGEXP
不支持\s
和\d
.
as MySQL REGEXP
does not support \s
and \d
.
[:blank:]
匹配空格和制表符,而[0-9]
匹配任何ASCII数字.
The [:blank:]
matches spaces and tabs, and [0-9]
matches any ASCII digit.
这篇关于MySQL REGEXP不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!