首页 > 解决方案 > 替换但在锚文本中除外

问题描述

是否可以替换 html 文本中的字符串,但除非它在超链接标签(锚文本)中。

例如:

The name of my dog is Mike. I always <a href="....">walk with my dog here</a>.

比用cat替换dog,而不是锚文本中的 dog 。所以结果应该是:

The name of my cat is Mike. I always <a href="....">walk with my dog here</a>.

标签: phpregex

解决方案


这只会在它不在>and之间时选择“dog” </a>

(dog)+(?![^>]*\</a>)


推荐阅读