@H_404_0@
PHP正则表达式学习笔记分享:
@H_4040@<span style="color: #800000">
1.创建正则表达式
@H4040@
<span style="color: #808080">$regex = '/\d/i';
与JavaScript中的第一个方式有点像,只是这里的话是个字符串。
@H4040@
<span style="color: #800000">2.正则表达式中的特殊字符
@H4040@特殊字符有: <span style="color: #808080">
. \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
@H404_0@<span style="color: #800000">
3.正则表达式中的函数
@H_404_0@有8个方法,
preg_match与preg_match_all,preg_replace与preg_replace_callback,preg_grep、preg_split、preg_last_error和pregquote。
@H404_0@
<span style="color: #3366ff">pregmatch:
@H404_0@执行一个正则表达式匹配
<p style="text-align: center">
@H_404_0@<span style="color: #800000">返回 pattern 的匹配次数。 它的值将是0次(不匹配)或1次,因为preg_match()在<span style="color: #800000">第一次匹配后,将会停止搜索。
<div class="jb51code">
<pre class="brush:PHP;">
$subject = "dd133aa2";
$pattern = '/\d+/';
preg_match($pattern,$subject,$matches,PREG_OFFSET_CAPTURE);
print_r($matches);