可以使用 断言 实现

正则表达式的先行断言和后行断言一共有4种形式:
(?=pattern) 零宽正向先行断言(zero-width positive lookahead assertion)
(?!pattern) 零宽负向先行断言(zero-width negative lookahead assertion)
(?<=pattern) 零宽正向后行断言(zero-width positive lookbehind assertion)
(?<!pattern) 零宽负向后行断言(zero-width negative lookbehind assertion)
这里面的pattern是一个正则表达式。

 

$pattern = "/<p>((.(?!<p>))*)<\/p>/";

$str = "<p>ggfgfhhghgh&nbsp;</p><p>ggfgfhhghgh&nbsp;</p>";

$res = preg_match_all($pattern, $str, $matches);

 

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2021-12-22
  • 2022-01-09
猜你喜欢
  • 2021-11-13
  • 2021-11-21
  • 2022-01-03
  • 2021-12-01
  • 2021-11-15
  • 2021-07-11
相关资源
相似解决方案