VBScript RegEx-单词之间的匹配

时间:2018-11-06 20:58:27

标签: regex vbscript

我很难想出可以用VBScript编写的RegEx。我正在尝试匹配2个关键字之间的所有文本:

(?<=key)(.*)(?=Id)

这将在VBScript中引发RegEx错误。 ID

我要匹配的Blob:

\"key\":[\"food\",\"real\",\"versus\",\"giant\",\"giant gummy\",\"diy candy\",\"candy\",\"gummy worm\",\"pizza\",\"fries\",\"spooky diy science\",\"spooky\",\"trapped\"],\"Id\"

理想情况下,我最终得到一个以逗号分隔的列表,如下所示:

food,real,versus,giant,giant gummy,diy candy,candy,gummy worm,pizza,fries,spooky diy science,spooky,trapped

但是,我想为在VBScript中工作的2个关键字之间的所有文本做好准备。

谢谢!

1 个答案:

答案 0 :(得分:1)

VBScript的正则表达式引擎不支持后置断言,因此,您需要执行以下操作:

s = "\""key\"":[\""food\"",\""real\"",\""trapped\""],\""Id\"""

'remove backslashes and double quotes from string
s1 = Replace(s, "\", "")
s1 = Replace(s1, Chr(34), "")

Set re = New RegExp
re.Pattern = "key:\[(.*?)\],Id"

For Each m In re.Execute(s1)
    list = m.Submatches(0)
Next

WScript.Echo list