gpt4 book ai didi

regex - VBA 正则表达式和组

转载 作者:行者123 更新时间:2023-12-04 03:05:56 25 4
gpt4 key购买 nike

在以下电子邮件正文中应用以下正则表达式:

(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

关于regex - VBA 正则表达式和组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44401036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com