Home > Backend Development > PHP Tutorial > Doubts about regular expressions w and d regular expression numbers python regular expression grep regular expression

Doubts about regular expressions w and d regular expression numbers python regular expression grep regular expression

WBOY
Release: 2016-07-29 08:49:53
Original
1058 people have browsed it

<code><span><span><?php</span><span>$string</span>=<span>'April15,2003'</span>;
<span>$pattern</span>=<span>'/(\w+)(\d+),(\d+)/i'</span>;
<span>$replacement</span>=<span>'${1},${3}'</span>;
<span>echo</span> preg_replace(<span>$pattern</span>,<span>$replacement</span>,<span>$string</span>);
<span>?></span></span></code>
Copy after login

这个表达式的结果为April1,2003
原因:(\w+)能够完整匹配April15,但是因为在(\w+)后面有(\d+),为了能够匹配定义的规则,(\w+)会匹配April1,(\d+)会匹配5
可以换个表达式避免出现这种情况如:
$pattern=’/([a-z])(\d+),(\d+)/i’;

欢迎自学PHP的加入PHP入门群交流 225128823

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了正则表达式\w和\d的疑惑,包括了正则表达式方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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