正则表达式 剖解preg_match()
[ ]不是子模式,不会在结果集里面列出。
( )中的东西,如果不是(?: ),就会出现在结果集中。
在结果数组中,0索引指向整个表达式匹配结果,往后1、2、3、4分别代表第1、2、3、4个子模式的匹配结果。结果中子模式顺序按开始括号的前后排序。
比如你写
$str='hello12345@xxx.abcdef';
$pattern='/(.*?)([0-9]+)/';
preg_match($pattern,$str,$match);
你会得到
array(
0 => 'hello12345',
1 => 'hello',
2 => '12345'
)