我有一个超级糟糕的数据集,没有真正的模式,我只需要找到3到7位的数字序列,这就是我一直在尝试的,但是matches.Count总是给出0。
Function catchNumbers(inSt As String)
Dim regex As Object, str As String
Set regex = CreateObject("VBScript.RegExp")
With regex
.Pattern = "\d{3-7}"
.Global = True '
.IgnoreCase = True
End With
inSt = Replace(inSt, ".", "")
Set matches = regex.Execute(inSt)
Debug.Print (matches.Count())
If matches.Count() > 0 Then
For Each StrFound In matches
Debug.Print (TypeName(StrFound) & " : " & StrFound)
str = str & " " & StrFound
Next StrFound
Else
str = ""
End If
If Left(str, 1) = " " Then
str = Right(str, Len(str) - 1)
End If
Debug.Print (str)
catchNumbers = str
End Function数据集示例:
25.802;24.052/Guaiba 25.802;24.052/Guaiba 25.859,L3-ac,Fls.5;25.862,L3-ac,Fls。6;25.865,L3-ac,Fls.7;25.856,L3-ac,Fls.4 25.859,L3-ac,Fls.5;25.862,L3-ac,Fls.6;25.865,L3-ac,Fls.7;25.856,L3-ac,Fls.4.
发布于 2016-06-09 21:28:30
用逗号代替连字符:\d{3,7}
https://stackoverflow.com/questions/37736397
复制相似问题