|
xyh2732 发表于 2013-2-4 21:27
什么是正则表达式啊,可否帮帮忙啊!
以下函数没有测试,你试试看。
Function ReturnStr(s As String, match_str As String) As String
'功能:返回与正则表达式匹配的子字符串中的表达式
'参数:s--字符串,match_str--正则表达式
'引用:Microsoft VBScript Regular Expressions 5.5
'示例:msgbox ReturnStr("CEX120300000","^(\D+)\d+\w*&")
Dim re As New regexp
Dim objs As MatchCollection
Dim str as string
str=""
re.Pattern = match_str
re.IgnoreCase = True
re.Global = True
If re.Test(s) = True Then
Set objs = re.Execute(s)
str=objs(0).SubMatches(1)
End If
ReturnStr=str
Set re = Nothing
Set objs = Nothing
End Function |
|