Home  >  Article  >  Backend Development  >  帮小弟我看下这个正则

帮小弟我看下这个正则

WBOY
WBOYOriginal
2016-06-13 10:07:53860browse

帮我看下这个正则~

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$reg = "/(\d{2})\/\\1\/(\d{4})/";$text = '03/02/2009';


为什么匹配不到呢?把正则改成"/(\d{2})\/(\d{2})\/(\d{4})/"就能匹配到了

------解决方案--------------------
这不是明摆的么?

02 能和 \1匹配么?
------解决方案--------------------
$text = '03/03/2009'; 这样估计就可以了。
------解决方案--------------------
因为在字符串中,你的\d匹配的是第一个 \d{2}也就是 03,\1反向引用也是03,在$text是找不到 03/03/2009 的。

如果改为$text='03/03/2009'; 就会匹配到了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn