【发布时间】:2015-07-28 11:47:40
【问题描述】:
我正在尝试将此查询的结果与我用于 PHP 验证的正则表达式进行匹配。
select u.id,concat(u.address1,', ',u.zip,' ',u.city,', ',c.countryName) as Address
from User u join
country c on u.countryCode=c.countryCode
输出是
27 Avenue Pasteur, 14390 Cabourg, France
28 Avenue Pasteur, 14390 Cabourg, France
30 14390 Cabourg, France
29 Avenue Pasteur, 14390 Cabourg, France
我不会将其与以下正则表达式匹配并仅获得正确的结果。
/^(?:\\d+ [a-zA-Z ]+, ){2}[a-zA-Z ]+$/
我不确定如何使用 MYSQL REGEXP
类似
select u.id,concat(u.address1,', ',u.zip,' ',u.city,', ',c.countryName) as Address
from User u join
country c on u.countryCode=c.countryCode
where Address REGEXP '^st'
【问题讨论】:
-
该正则表达式不会匹配任何字符串,因为地址门牌号后面没有逗号。似乎还有其他问题。试图解决他们。
-
这更接近你在regex101.com/r/zN7yT1/1之后的样子。我不确定mysql支持什么修饰符,可能需要将
[a-z]变成[a-zA-Z]。 -
@icecub 不匹配 27 Avenue Pasteur, 14390 Cabourg, France
-
@dev1234 可能是我,但这是你的正则表达式,它与其中任何一个都不匹配:regex101.com/r/uP8qP4/1
-
我可以轻松编写您需要与@chris85 正则表达式匹配的代码。但我认为他首先应该为此受到赞扬,所以如果他想这样做,那就应该是他。