返回列表 上一主題 發帖

高手們幫幫 regexp 求教 找特定數量的數字

高手們幫幫 regexp 求教 找特定數量的數字

大大們好 想請問用 regexp 怎麼找6個位 或8個位的數字  , 而且以2 或 3 開頭?
以下是我的未完成範例 只能找到數字

Private Function format_dn(ByVal DN As String) As String


Set oregexp = CreateObject("vbscript.regexp")
With oregexp
    .Global = True
    .IgnoreCase = True
    .Pattern = "[0-9]+"
    .MultiLine = True
   
    Set omatch = .Execute(DN)
    'MsgBox (omatch(0))
   
    For Each m In omatch
        returntext = returntext & m & vbCrLf
    Next
    format_dn = returntext
   
    'replace the number then exist a-z
    'MsgBox .Replace(DN, "")


   
End With

End Function

請高手幫幫

回復 1# adrian_9832
樓主試試.Pattern = "(2|3)\d{5,7}" 這樣不知可否?

TOP

\b[23](\d{5}|\d{7})(?![\d\.])
世界那麼大,可我想去哪?

TOP

謝謝兩位大大的幫助

TOP

回復 1# adrian_9832

    謝謝前輩發表此主題
後學練習字典的解決方案,請前輩參考

[A1]="asd1234567890,f0987654321,c3567890,d2456789012,0.34567890132,-0.2547896543,S234,000,F25533.000,G33366666,000000"


Option Explicit
Private Function format_dn(ByVal DN As String) As String
Dim T$, N&, Y, i
Set Y = CreateObject("Scripting.Dictionary")
For i = 1 To Len(DN) - 5
   T = Mid(DN, i, 8): N = Val(T): T = N
   If T Like "2#######" Or T Like "3#######" Then Y(T & "") = ""
   T = Mid(T, 1, 6)
   If T Like "2#####" Or T Like "3#####" Then Y(T & "") = ""
Next
If Y.Count = 0 Then
   format_dn = ""
   Else
      format_dn = Join(Y.KEYS, vbCrLf)
End If
Set Y = Nothing
End Function
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流

TOP

        靜思自在 : 改變自己是自救,影響別人是救人。
返回列表 上一主題