繁体   English   中英

PHP的preg_match_all和递归rexep

[英]php preg_match_all and recursive rexep

我在生成文件时遇到了一些麻烦,我想进行一些替换

说我有这种模式:

<ul/><htmlelement>some text</htmlelement>

我想用我的regexep查找一些文本的值,因为我可以找到带有regexp的htmlelement元素,所以我想像这样在regex中递归地包含它

preg_match_all("#<ul/><([^><])>(.)*</(first capuring match)>#", $string, $matches);

你有解决方案吗?

  1. 您会错过“ htmlelement”开始标记的+量词。

  2. 您需要在捕获组中添加*

  3. 并更好地使其与?

  4. 请用\\1指代“第一次捕获匹配”。

因此,正则表达式应为:

<ul\/><([^><]+)>(.*?)<\/\1>
             ^    ^^     ^
             1    23     4

演示: https : //regex101.com/r/f25N9J/1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM