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

帮小弟我看下这个正则

WBOY
Release: 2016-06-13 13:38:16
Original
884 people have browsed it

帮我看下这个正则~

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$reg = "/(\d{2})\/\\1\/(\d{4})/";
$text = '03/02/2009';

Copy after login


为什么匹配不到呢?把正则改成"/(\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'; 就会匹配到了。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template