Regex VBA正则表达式和组

Regex VBA正则表达式和组,regex,vba,Regex,Vba,在下面的电子邮件正文上应用下面的正则表达式: (pls[a-zA-Z0-9 .*-]*) \(([A-Z 0-9]*)\) pls18244a.lam64*fra-pth (PI000581) pls18856a.10ge*fra-pth (PI0005AW) pls25040a.10ge*fra-pth (IIE0004WK) pls27477a.10ge*fra-pth (WL050814) pls22099a.stm4*par-pth (PI0005TE) 电子邮件正文: (p

在下面的电子邮件正文上应用下面的正则表达式:

(pls[a-zA-Z0-9 .*-]*) \(([A-Z 0-9]*)\)
pls18244a.lam64*fra-pth (PI000581) 
pls18856a.10ge*fra-pth (PI0005AW) 
pls25040a.10ge*fra-pth (IIE0004WK) 
pls27477a.10ge*fra-pth (WL050814) 
pls22099a.stm4*par-pth (PI0005TE)
电子邮件正文:

(pls[a-zA-Z0-9 .*-]*) \(([A-Z 0-9]*)\)
pls18244a.lam64*fra-pth (PI000581) 
pls18856a.10ge*fra-pth (PI0005AW) 
pls25040a.10ge*fra-pth (IIE0004WK) 
pls27477a.10ge*fra-pth (WL050814) 
pls22099a.stm4*par-pth (PI0005TE)

返回5个匹配项,包含两个组。使用增量变量复制excel行中的每个匹配组来获取每个匹配组的VBA脚本是什么?

不更改正则表达式模式。使用以下方法,可以迭代每个匹配的组:

str="pls18244a.lam64*fra-pth (PI000581)pls18856a.10ge*fra-pth (PI0005AW)pls25040a.10ge*fra-pth (IIE0004WK)pls27477a.10ge*fra-pth (WL050814)pls22099a.stm4*par-pth (PI0005TE)"
Set objReg = New RegExp
objReg.IgnoreCase=False
objReg.Global=True
objReg.Pattern = "(pls[a-zA-Z0-9 .*-]*) \(([A-Z 0-9]*)\)"
Set objMatches = objReg.Execute(str)
For Each match In objMatches             'The variable match will contain the full match
    a= match.Submatches.Count            'total number of groups in the full match  
    For i=0 To a-1
        MsgBox match.Submatches.Item(i)  'display each group
    Next
Next
Set objReg = Nothing

match
对象有一个
submatches
集合,所以每次匹配时都要循环该集合。谢谢,(for each)句子应该是包含匹配项而不是匹配项。。我需要得到1stmatch.1stgroup和1stmatch.2ndgroup,依此类推。。在不同的领域?有谁能帮忙吗?我不明白你说的?你现在有了完整的工作代码。它将显示每场比赛的两组。是否要显示整个比赛?