【发布时间】:2011-05-01 23:35:49
【问题描述】:
我需要以不区分大小写的方式查找和替换所有文本匹配项,除非文本位于锚标记内 - 例如:
<p>Match this text and replace it</p>
<p>Don't <a href="/">match this text</a></p>
<p>We still need to match this text and replace it</p>
搜索“匹配此文本”只会替换第一个实例和最后一个实例。
[编辑] 根据 Gordon 的评论,在这种情况下可能更喜欢使用 DOMDocument。我完全不熟悉 DOMDocument 扩展,并且非常感谢此功能的一些基本示例。
【问题讨论】:
-
在这里使用 DOM as shown 并适应
-
锚内嵌套标签的首选行为是什么,例如
<p>This is <a href="#">a link <span>with <strong>don't match this text</strong> content</span></a></p>?
标签: php regex xpath preg-replace domdocument