|
Sub t343()
Dim regex As New RegExp
Dim sr, mat, m
sr = "100980009579"
With regex
.Global = True
.Pattern = "\d+(?=\9)\d" '查找任意多数字后的元,查找到后从元以前开始查找,查找和\d匹配的。
Set mat = .Execute(sr)
For Each m In mat
Debug.Print m
Next m
End With
End Sub
请教这个程序为什么不返回1009,80009,579三行结果呢?而返回100980009579呢?
9在正则里没有特殊意义,所以不用转义符。
\d+,这是贪婪模式,在100980009579匹配时,会匹配到最后一个9时才结束,也就是10098000957,然后再\d后,就成了100980009579了。
|
|