过滤掉字符串中的锚标签
时间:2020-03-05 18:42:41 来源:igfitidea点击:
我需要过滤掉字符串中的锚标签。例如,
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, "", RegexOptions.IgnoreCase)