0

I'm coding in VBSscript.

I have the following string

myString = "[ "http://www.google.com/", "http://www.yahoo.com" ]

How can I extract the urls with regexp? is there anyway to read this JS array?

1
  • I agree with Bartdude, it seems to be the best route and simple too, using the SPLIT function will return an array of elements too, and will work on any number of elements (within reason). I would have posted the SAME solution as BArtdude and as he has done so already, there seems no point in re-iterating what he has stated. Commented May 11, 2013 at 12:40

2 Answers 2

2

I would remove starting and trailing brackets, then use the split method. I don't think regex are intended to do that...

Sign up to request clarification or add additional context in comments.

Comments

0

RegExp for easy cases (no embeded "):

  ' Mark the correct quotes
  Dim sTest : sTest = "[ ""http://www.google.com/"", ""http://www.yahoo.com"", """" ]"
  WScript.Echo sTest
  Dim reStringLiteral : Set reStringLiteral = New RegExp
  reStringLiteral.Global  = True
  reStringLiteral.Pattern = """([^""]*)"""
  Dim oMTS : Set oMTS = reStringLiteral.Execute(sTest)
  Dim oMT
  For Each oMT In oMTS
      WScript.Echo oMT.Value, oMT.SubMatches(0)
  Next

output:

[ "http://www.google.com/", "http://www.yahoo.com", "" ]
"http://www.google.com/" http://www.google.com/
"http://www.yahoo.com" http://www.yahoo.com
""

Split() for easy cases (invariant ", " separator):

  Dim sTest : sTest = "[ ""http://www.google.com/"", ""http://www.yahoo.com"", """" ]"
  WScript.Echo sTest
  Dim reNetto : Set reNetto = New RegExp
  reNetto.Global  = True
  reNetto.Pattern = "^[^""]*""|""[^""]*$"
  sTest = reNetto.Replace(sTest, "")
  WScript.Echo sTest
  Dim sUrl
  For Each sUrl In Split(sTest, """, """)
      WScript.Echo qq(sUrl), sUrl
  Next

output:

[ "http://www.google.com/", "http://www.yahoo.com", "" ]
http://www.google.com/", "http://www.yahoo.com", "
"http://www.google.com/" http://www.google.com/
"http://www.yahoo.com" http://www.yahoo.com
""

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.