在VBA中,匹配以下每个字符串的正则表达式是什么?
第一个:
56-...
第二个:
...-28
对于第二个,我尝试了以下方法,但没有结果:
Target.Value Like "[\.]{3}[\-]{1}[0-9]{1,}"
请尝试一下。
Option Explicit
Sub demo()
Dim sTxt As String, oMatch As Object
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "\d+-\.{3}"
sTxt = "the frist one 56-..."
For Each oMatch In .Execute(sTxt)
Debug.Print oMatch.Value
Next
.Pattern = "\.{3}-\d+"
sTxt = "For the second one...-28"
For Each oMatch In .Execute(sTxt)
Debug.Print oMatch.Value
Next
End With
End Sub
输出:
56-...
...-28