【发布时间】:2017-12-08 13:17:13
【问题描述】:
我很难在一段内容中尝试用<h2> 替换<h1> 标记。
我得到的最接近的是:
preg_replace('/<h1[\s*](class|id|style)="(.*?)">(\w*?)<\/h1>/mi', '<h2 $1="$2">$3</h2>', $content);
这里的问题是常规的 h1 行:
<h1>This is the heading</h1>
不会被捕获。
这一行:
<h1 style="font-size:13px">Another heading</h1>
也不会被捕获,这让我感到困惑,因为它使用与 class 和 id 相同的设置,仅使用特殊字符,例如 -、: 等。我以为.*? 会覆盖。
任何帮助将不胜感激。
【问题讨论】:
标签: php regex preg-replace regex-group