判断【patten】和【字符串】是否匹配成功
'Test:返回一个布尔值,该值指示正则表达式是否与字符串成功匹配。
'Dim s As String '字符串
'Dim p As String '正则表达式
Function bTest(ByVal s As String, ByVal p As String, Optional ByRef val As String = "-10001") As Boolean
Dim re As Object
Set re = CreateObject("Vbscript.Regexp")
re.IgnoreCase = False '设置是否匹配大小写
re.Pattern = p
bTest = re.test(s)
If val <> "-10001" And bTest Then
Dim mMatches As Object '匹配字符串集合对象
Dim mMatch As Object '匹配字符串
Set mMatches = re.Execute(s) '执行正则查找,返回所有匹配结果的集合,若未找到,则为空
val = mMatches(0).SubMatches(0)
' For Each mMatch In mMatches
' getValueRegex = getValueRegex + mMatch.Value
' Next
Else
val = "不匹配"
End If
End Function