vba 正则表达式只返回第一个匹配项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12300848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vba regex only returns first match
提问by Vince V.
my regex match in VBA (WORD) only gives one result.
我在 VBA (WORD) 中的正则表达式匹配只给出一个结果。
I created this function
我创建了这个函数
Function RE6(strData As String) As String
Dim RE As Object, REMatches As Object
Set RE = CreateObject("vbscript.regexp")
With RE
.MultiLine = False
.Global = False
.IgnoreCase = True
.Pattern = "\[substep [a-zA-Z]\](.*?); {1}"
End With
Set REMatches = RE.Execute(strData)
RE6 = ""
End Function
The problem here is that it only gives the first result. For example I got a string:
这里的问题是它只给出第一个结果。例如我得到一个字符串:
[step 1] title for substeps; [substep a] step a; [substep b] step b; [substep c] step c;
My result is:
我的结果是:
[substep a] step a;
[子步骤a]步骤a;
only 1 match, not the step b and c.
只有 1 个匹配,而不是步骤 b 和 c。
回答by marg
You need to set Global to True
您需要将 Global 设置为 True
http://msdn.microsoft.com/en-us/library/tdte5kwf%28v=vs.84%29
http://msdn.microsoft.com/en-us/library/tdte5kwf%28v=vs.84%29