我想匹配在我的HTML內容,變量的所有鏈接,其中的href開始與http://www.example.com在HTML更換標籤正則表達式這裏的href屬性以http://
例
應符合:
<a href="http://www.example.com">foo</a>
不應該匹配:
<a href="/bar/">bar</a>
也匹配(與換行符和其他HTML標籤內錨):
<a class="bla" id="blubb" href="http://www.example.com/asdf/" title="oops">
<img src="..." alt="" />
</a>
我開始是這樣的:
<CFSAVECONTENT variable="html">
<a class="bla" id="blubb" href="http://www.example.com/asdf/" title="oops">
<img src="..." alt="" /> some Text
</a>
</CFSAVECONTENT>
<CFSET result = REReplace(html, "<a[^>]*href="http://www\.example\.com[^"]*"[^>]?>([^<]+)</a>", "\1") />
但當然這其中不匹配我的最後一個鏈接的例子與在標籤內的img-tag ...
這個的任何提示?
經過進一步調查,問題標題與您所問的內容不符:您是否想要匹配以http://開頭的所有鏈接,或是否所有以http://www.example.com開頭的鏈接?我必須根據你想要的來修改我的答案。 –
它應該匹配所有以http://www.example.com開頭的鏈接 – Seybsen
然後我的回答如下。 –