VB如何捕获正则表达式分组的值?例如:
\<a target\="_blank" href\=\"(?<url>.+?)\" title\=\"(?<title>.+?)\"\>.+?(\<\/a\>)用VB如何获得分组Title的值?请给我例子,谢谢!!
\<a target\="_blank" href\=\"(?<url>.+?)\" title\=\"(?<title>.+?)\"\>.+?(\<\/a\>)用VB如何获得分组Title的值?请给我例子,谢谢!!
<a href="http://www.xxx.com" title="xxxxxx">this is a link</a>在上述字符串中,用正则表达式
<a href="(.+?)" title="(.*?)">.+?</a>可以取得href,title的值。代码如下:set MyReg = New RegExp
MyReg.IgnoreCase = true
MyReg.Global = trueMyReg.Pattern = "<a href=""(.+?)"" title=""(.*?)"">.+?</a>"
set myMatches = MyReg.Execute(filecontent)href = MyReg.Replace(myMatches(0),"$1")
title = MyReg.Replace(myMatches(0),"$2")使用以上代码就取到了相应的值。其实就是利用replace方法,用分组值替换了整个字符串。
filecontent = "<a href=""http://www.xxx.com"" title=""xxxxxx"">this is a link</a>"