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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:36:32  来源:igfitidea点击:

vba regex only returns first match

regexvba

提问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。