在 vbscript 中使用 Regexp.Execute 时出错
in vbscript an Error when using Regexp.Execute
在 vbscript 中使用正则表达式 EXECUTE 函数时,当有匹配项时程序会继续,但是当没有匹配项时程序会抛出错误并崩溃。有没有办法解决这个问题,解决方法?提前致谢。
dim object_str : object_str = "cup of tea"
Set compare_exp = new RegExp
compare_exp.IgnoreCase = False
compare_exp.Global = True
compare_exp.Pattern = "tea1"
wscript.echo compare_exp.Execute(object_str).Item(0).Value
wscript.echo "continue"
确保正则表达式在尝试读取结果之前找到匹配项:
dim object_str : object_str = "cup of tea"
Set compare_exp = new RegExp
compare_exp.IgnoreCase = False
compare_exp.Global = True
compare_exp.Pattern = "tea1"
dim result: set result = compare_exp.Execute(object_str)
if result.count > 0 then
wscript.echo result.Item(0).Value
else
wscript.echo "no match"
end if
在 vbscript 中使用正则表达式 EXECUTE 函数时,当有匹配项时程序会继续,但是当没有匹配项时程序会抛出错误并崩溃。有没有办法解决这个问题,解决方法?提前致谢。
dim object_str : object_str = "cup of tea"
Set compare_exp = new RegExp
compare_exp.IgnoreCase = False
compare_exp.Global = True
compare_exp.Pattern = "tea1"
wscript.echo compare_exp.Execute(object_str).Item(0).Value
wscript.echo "continue"
确保正则表达式在尝试读取结果之前找到匹配项:
dim object_str : object_str = "cup of tea"
Set compare_exp = new RegExp
compare_exp.IgnoreCase = False
compare_exp.Global = True
compare_exp.Pattern = "tea1"
dim result: set result = compare_exp.Execute(object_str)
if result.count > 0 then
wscript.echo result.Item(0).Value
else
wscript.echo "no match"
end if