日期:2014-05-17  浏览次数:20548 次

熟悉正则的进来下,0宽断言中使用重复*会报错
大家看看这两个。
PHP code
preg_match('#(?<=a*)word#',' pre word',$mt);
preg_match('#(?<=<(\w+)>).*(?=<\/\1>)#',' pre<a>hi!</a> word',$mt);



------解决方案--------------------
http://perldoc.perl.org/perlretut.html#Looking-ahead-and-looking-behind
这是perl的正则文档,觉得应该可以适用php的正则引擎
里面有一句 The lookahead assertion is denoted by (?=regexp) and the lookbehind assertion is denoted by (?<=fixed-regexp)
零宽断言也叫环视,上面的意思是逆序环视只能包含固定长度的子表达式,所以不能出现 * ? +这些量词,只有顺序环视可以