1

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

1 Answer 1

1

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:

Dim objRegExp
Set objRegExp = New RegExp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = ""((https?:\/\/|www.)([-\w.]+)+(:\d+)?(\/([\w\/_.]*(\?\S+)?)?)?)""

dim matches()
dim i: i = 0

Dim objMatch
For Each objMatch in objRegExp.Execute(strHTML)
   redim preserve matches(i)
   matches(i) = objMatch.SubMatches(0)
   i = (i + 1)
Next

Set objxmlHTTP = Nothing

'//read back
for i = 0 to ubound(matches)
   wscript.echo matches(i)
next
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.