首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按顺序查找所有数字的Regex

按顺序查找所有数字的Regex
EN

Stack Overflow用户
提问于 2016-06-09 21:21:56
回答 1查看 101关注 0票数 0

我有一个超级糟糕的数据集,没有真正的模式,我只需要找到3到7位的数字序列,这就是我一直在尝试的,但是matches.Count总是给出0。

代码语言:javascript
复制
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.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-09 21:28:30

用逗号代替连字符:\d{3,7}

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37736397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档