首页  >  文章  >  后端开发  >  php中Warning: preg_match_all(): Compilation failed: lookbehind assertion

php中Warning: preg_match_all(): Compilation failed: lookbehind assertion

WBOY
WBOY原创
2016-07-25 08:46:432095浏览
今天在测试正则表达式中相关环视的代码时,发现有个错误
错误信息如下:
Warning: preg_match_all(): Compilation failed: lookbehind assertion is not fixed length at offset
代码如下:
  1. $str='
    info
    strong';
  2. preg_match_all('/(?]*>).*(?=)/',$str,$match);
  3. var_dump($match);
复制代码
执行上面的代码就会报错,在网上查看下,说php中逆序环视(包括逆序肯定环视 ?
将上面的代码改为:
  1. $str='
    info
    strong';
  2. preg_match_all('/(?).*(?=)/',$str,$match);
  3. var_dump($match);
复制代码
但这种只能匹配b标签中strong内容
其实,不用环视来匹配,直接用分组来捕获内容,只是这样要在返回的结果中筛选一下
  1. $str='
    info
    strong';
  2. preg_match_all('/(]*>)(.*)()/',$str,$match);
  3. print_r($match[3]);//Array ( [0] => info [1] => strong )
复制代码




声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn