Heim  >  Artikel  >  Backend-Entwicklung  >  php中Warning: preg_match_all(): Compilation failed: lookbehind assertion

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

WBOY
WBOYOriginal
2016-07-25 08:46:432095Durchsuche
今天在测试正则表达式中相关环视的代码时,发现有个错误
错误信息如下:
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 )
复制代码




Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn