一、写一个自定义函数:
Function ReplaceMatch(ByVal str As String, ByVal match_str As String, ByVal Rematch_str As String) As String
'引用:Microsoft VBScript Regular Expressions 5.5
'功能:替换字符串
'参数:Test_str--测试字符串,match_str--源正则表达式,Rematch_str--替换的正则表达式
Dim re As New regexp
re.Pattern = match_str
re.IgnoreCase = True
re.Global = True
ReplaceMatch = re.Replace(str, Rematch_str)
Set re = Nothing
End Function
二、用该函数提取数字后面的的文字:
str=ReplaceMatch(me.listbox.value,"^\d+","") ' "^\d+"为正则表达式,表示匹配开始是一位或多位数字的字符串
Function cutNumber(chkStr As String) As String
'检测字符串中头几位数字的位数,将其截除
Dim i As Long, lenNumber As Long
For i = 1 To Len(chkStr)
If IsNumeric(Mid(chkStr, i, 1)) = False Then
lenNumber = i - 1
Exit For
End If
Next i
cutNumber = Right(chkStr, Len(chkStr) - lenNumber)
End Function
总记录:6篇 页次:1/1 9 1 :