我有一个正则表达式,用于替换短语,如果该短语不包含HTML锚标记或IMG标记。在这个例子中被搜索的短语是 “Hello World” 的如何将.Net正则表达式转换为php
的.NET正则表达式是
(?<!<a [^<]+)(?<!<img [^<]+)(?<=[ ,.;!]+)hello world(?=[ ,.;&!]+)(?!!.*</a>)
E.G.正则表达式应该在一个短语匹配 “世界你好” 之类
"one two three hello world four five"
但在一个短语像
"one two three <a href='index.html'> hello world </a> four five"
或
"one two three <img alt='hello world' \>four five"
它与相关的应该不匹配的Hello World以下是我最初开发.Net版本时的问题。 regular expression that doesn't match a string if it's the text within an html anchor tag
任何有关如何将其转换为PHP正则表达式的指导将非常感激。
这个正则表达式不能匹配任何.NET也。结束标记有一个斜杠(''),但表达式会查找反斜杠。 –
@DanielHilgarth感谢您的纠正,我已经更新了这个问题。 – Rich
现在有什么问题? –