Regex 删除href标记和内容coldfusion

Regex 删除href标记和内容coldfusion,regex,coldfusion,tags,href,Regex,Coldfusion,Tags,Href,我们如何从以下内容中删除: This is some text. It is true that <a href="http://www.cnn.com">Harry Potter</a> is a good 我用过正则表达式。* 但它不起作用 <[aA][^>]*>[^<>]*<\/[aA]> 尝试此操作。替换为空字符串 见演示 看。它应该工作得很好 --以下是我拙劣的回答:-- 这应该是你想要的。您可能遇到的唯一问题是链接

我们如何从以下内容中删除:

This is some text. It is true that <a href="http://www.cnn.com">Harry Potter</a> is a good
我用过正则表达式。*

但它不起作用

<[aA][^>]*>[^<>]*<\/[aA]>
尝试此操作。替换为空字符串

见演示

看。它应该工作得很好

--以下是我拙劣的回答:--

这应该是你想要的。您可能遇到的唯一问题是链接标记contains>的任何属性

<cfset mystring = 'This is some text. It is true that <a href="http://www.cnn.com\">Harry Potter</a> is a good, but <a href="gooogle_redirect.htm">Google</a> is better'>
<cfset mystring2 = ReplaceNoCase(mystring,"</a>","","ALL")>
<cfset MyReplace = ReReplaceNoCase(mystring2,"<a [^>]*>","","ALL")>

<cfoutput><pre>Original string: #mystring#

Without link: #myreplace#</pre></cfoutput>
替代方法:如果要删除链接和链接的文本,而不仅仅是链接,则此方法非常有用。这是我一直使用的肮脏的解决方法。我认为也许其他语言可以做到这一点,但CF并不完全支持正则表达式

找到一个字符,一个单一的字符,你知道它不包含在你的任何链接文本之间是一个好的,但更好

这是一些文本。这的确是一个好主意,但更好


如果要删除整个链接和文本,只需从上面的“重新放置”框中取出\1即可。

假设要保留超链接之间的文本:

将导致:

这是一些文本。《哈利·波特》的确是一部好电影


@swetha检查了正则表达式的coldfusion。它很相似。肯定还有其他问题。你是如何申请的it@vks这至少在cf9中是有效的,我不明白为什么它在早期的v中不起作用。它甚至可以拾取多个链接。干得好如果OP愿意,可以将代码中的\1替换为。好的Job@swetha考虑到上面的代码示例,他的答案确实有效。在cflive.net form.textcontet MATCHDATA上测试您遇到了什么错误???如果你得到一些输出,那是什么?编辑你的问题,添加代码。它将更具可读性,您将更有可能获得帮助。@swetha:评论是暂时的。请将您的问题包括在代码中。
<cfset closer="~">
<cfset mystring = 'This is some text. It is true that <a href="http://www.cnn.com\">Harry Potter</a> is a good, but <a href="gooogle_redirect.htm">Google</a> is better'>
<cfset mystring2 = ReplaceNoCase(mystring,"</a>","#closer#","ALL")>
<cfset MyReplace = ReReplaceNoCase(mystring2,"<a [^>]*>([^#closer#]*)#closer#","","ALL")>

<cfoutput><pre>Original string: #mystring#

Without link: #myreplace#</pre></cfoutput>
<cfsavecontent variable="content">
   This is some text. It is true that <a href="http://www.cnn.com">Harry Potter</a> is a good
</cfsavecontent>

<cfset content = reReplaceNoCase(content, "(<a.*?>)(.*?)(</a>)", "\2", "all") />
<cfoutput>#content#</cfoutput>