正向预搜索 "(?=xxxxx)","(?!xxxxx)" 正则表达式
二、预搜索
预搜索是一个非获取匹配,不进行存储供以后使用。
1、正向预搜索 "(?=xxxxx)","(?!xxxxx)"
"(?=xxxxx)”:所在缝隙的右侧,必须能够匹配上 xxxxx 这部分的表达式,
<?php $str = 'windows NT windows 2003 windows xp'; preg_match('/windows (?=xp)/',$str,$res); print_r($res);
结果:
Array
(
[0] => windows
)
这个是xp前面的windows,不会取NT和2003前面的。
格式:"(?!xxxxx)",所在缝隙的右侧,必须不能匹配 xxxxx 这部分表达式
全文:http://www.cnblogs.com/phpzxh/archive/2011/01/13/1934995.html