我有情况,我已经下面的内容是这样正则表达式来删除外部链接与出文字
This is a <a href="https://www.test.com">test1</a>. This is <a href="/node/1">test2</a>. This is <a href="https://nct.com">test3</a>. This is a <a href="www.test.com">test4</a>. This is a <a href="http://test.com">test5</a>.
nct.com是我的网站。我不想删除包含在标签内的链接和文本。那么/ node/1。
我期待的输出是
This is a test1. This is <a href="/node/1">test2</a>. This is <a href="https://nct.com">test3</a>. This is a test4. This is a test5.
凡为外部网站如test.com,我想一个标签内容不去除包装标签中的文本。我使用
钍正则表达式是
#<a [^>]*\bhref=(['"])http.?://((?<!mywebsite)[^'"])+\1 *.*?</a>#i
这将删除标记内容以及在标签中的文本。
你需要nct.com和/ node/1在正则表达式中硬编码还是只有url没有http(s)? – Wouter