简体   繁体   English

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

I try to query my MySql database for this regex using this query: 我尝试使用以下查询来查询此正则表达式的MySql数据库:

SELECT
    *
FROM
    `everything`.`instances_meta` AS m
WHERE
    `meta.value` REGEXP "[1,+][\s.-]\d{3}[\s.-]\d{3}[\s.-]\d{4}" 

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. 我会指定正则表达式引擎,但不确定MySql使用什么。

Use 采用

"[1,+][[:blank:].-][0-9]{3}[[:blank:].-][0-9]{3}[[:blank:].-][0-9]{4}"

as MySQL REGEXP does not support \\s and \\d . 因为MySQL REGEXP不支持\\s\\d

The [:blank:] matches spaces and tabs, and [0-9] matches any ASCII digit. [:blank:]匹配空格和制表符, [0-9]匹配任何ASCII数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM