正则:如何处理嵌套的HTML标签中的内容?
我想用正则表达式处理html中的文本,因为处理的同时还要保证html标签,所以不能用innerText。
代码如下:
在处理嵌套的HTML时,这个正则匹配有问题,
如处理:<ul><li>列表中的Text</li></ul>时,match.SubMatches(2)是空。
而我需要得到的内容是“列表中的Text”或者“<li>列表中的Text</li>”
大家帮我看看,应该怎么修改这个正则。
<script type="text/vbscript">
<!--
p_template = "<aaa>自定义标签</aaa><ul>aa<li>列表中的Text</li>aa</ul><p><img src='http://wwwy1.asdfs.com' width='100px' height='50' />P中间IMG后面的 文字</p><a href='mailto:aa?subject=bb&body=cc'>这个是链接文字</a>链接后 的文字"
Set p_regexp = New RegExp
p_regexp.Global = True
p_regexp.Pattern = "<([a-z]+)(.*)>(.*)<\/\1>"
'While p_regexp.Test(p_template)
'MsgBox p_template
Set Matches = p_regexp.Execute(p_template)
For Each match in Matches
'If p_regexp.Test(p_template)
p_regexp.Pattern = match.Value
p_template = p_regexp.Replace(p_template, match.SubMatches(2))
MsgBox match.SubMatches(2)
Next
'Wend
MsgBox p_template
//-->
</script>