我需要在字符串中过滤掉锚标记。例如,

Check out this site: <a href="http://www.stackoverflow.com">stackoverflow</a>

我需要能够将锚标记过滤掉:

Check out this site: http://www.stackoverflow.com

这种格式也许不一定。锚标签可能还有其他属性。此外,字符串中可能有多个锚标记。我在进入数据库之前在vb.net中进行过滤。

有帮助吗?

解决方案

这是一个应该有效的简单正则表达式。

Imports System.Text.RegularExpressions

' ....

Dim reg As New Regex("<a.*?href=(?:'|"")(.+?)(?:'|"").*?>.+?</a>")
Dim input As String = "This is a link: <a href='http://www.stackoverflow.com'>Stackoverflow</a>"
input = reg.Replace(input, "$1", RegexOptions.IgnoreCase)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top