0

我正在用 VBSscript 编码。

我有以下字符串

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

如何使用正则表达式提取网址?无论如何要读取这个JS数组吗?

4

2 回答 2

2

我会删除开始和结尾的括号,然后使用 split 方法。我不认为正则表达式打算这样做......

于 2013-05-03T12:55:08.020 回答
0

简单案例的正则表达式(没有嵌入“):

  ' 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

输出:

[ "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() 用于简单的情况(不变的“,”分隔符):

  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

输出:

[ "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
""
于 2013-05-03T20:30:22.540 回答