vbscript正则表达式转入数组
通过下面的代码,我尝试将使用正则表达式提取的每个 url 提取到一个数组中,稍后我可以调用该数组以及 url 计数。不知道如何抓住所有这些。
Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")
Call objxmlHTTP.open("GET", "website", False)
objxmlHTTP.Send()
strHTML = objxmlHTTP.ResponseText
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<a\s+href=""(http://.*?)""[^>]+>(\s*\n|.+?\s*)</a>"
Dim objMatch
For Each objMatch in objRegExp.Execute(strHTML)
objMatch.SubMatches(0)
Next
Set objxmlHTTP = Nothing
With the code below I am trying to pull each url I extract using the regular expression into an array that I can call later along with the count of urls. Not sure how to grab all of them.
Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")
Call objxmlHTTP.open("GET", "website", False)
objxmlHTTP.Send()
strHTML = objxmlHTTP.ResponseText
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<a\s+href=""(http://.*?)""[^>]+>(\s*\n|.+?\s*)</a>"
Dim objMatch
For Each objMatch in objRegExp.Execute(strHTML)
objMatch.SubMatches(0)
Next
Set objxmlHTTP = Nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用一个假字符串测试了这个,你的正则表达式结果看起来有点奇怪,所以我改变了它(摘自 此处)。第一场比赛的结果(您捕获了 2 场比赛?)被放置在 matches 数组中:
I tested this with a fake string, your regexp results seemed a bit wonky so I changed it (grabbed from here). Results of the 1st match (you capture 2?) are placed in the matches array: