正则表达式处理一下html
求一个正则表达式处理一下html
想去除html中除链接标记之外的所有标记,即字符串中遇到象 <...> 这样的部分,如果其中包含href或/a则保留,其余删除。
我原来是这么写的:
For Each m As Match In Regex.Matches(ss, " <[^> ]*> ", egexOptions.IgnoreCase)
If InStr(LCase(m.Value), "href ") < 1 AndAlso LCase(m.Value) <> " </a> " then
ss = Replace(ss, m.Value, " ")
End If
Next
不过我觉得这么作可能效率比较低,希望能通过一条正则表达式搞定。
------解决方案--------------------
try
<(?!(a\s|/a> ))[^> ]*?>
想去除html中除链接标记之外的所有标记,即字符串中遇到象 <...> 这样的部分,如果其中包含href或/a则保留,其余删除。
我原来是这么写的:
For Each m As Match In Regex.Matches(ss, " <[^> ]*> ", egexOptions.IgnoreCase)
If InStr(LCase(m.Value), "href ") < 1 AndAlso LCase(m.Value) <> " </a> " then
ss = Replace(ss, m.Value, " ")
End If
Next
不过我觉得这么作可能效率比较低,希望能通过一条正则表达式搞定。
------解决方案--------------------
try
<(?!(a\s|/a> ))[^> ]*?>