读书人

熟悉正则的进来下0宽断言中使用重复

发布时间: 2012-05-05 17:21:10 作者: rapoo

熟悉正则的进来下,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)
零宽断言也叫环视,上面的意思是逆序环视只能包含固定长度的子表达式,所以不能出现 * ? +这些量词,只有顺序环视可以

读书人网 >PHP

热点推荐