如何在VB脚本中以正则表达式模式包含空格?
对于此代码:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set file = objFSO.OpenTextFile("sample.txt" , ForReading)
Const ForReading = 1
Dim re
Set re = new regexp
re.Pattern = "(\w+?[(]\w+?[)];)"
re.IgnoreCase = True
re.Global = True
Dim line
Do Until file.AtEndOfStream
line = file.ReadLine
For Each m In re.Execute(line)
Wscript.Echo m.Submatches(0)
Next
Loop
使用sample.txt文件:
object();
object(string);
我想回应一下:
object();
object(string);
而不仅仅是这个:
object(string);
答案 0 :(得分:1)
按如下方式更改您的模式:
re.Pattern = "(\w+?[(]\w*?[)];)"
' ^ use * instead of + here
使用*
(零或多个)量词而不是+
(一个或多个)量词将让您匹配以下两者:
object();
object(string);