2016-10-06 12 views
1

私は以下のコードを試しましたが、最初の6桁の数字しか与えませんでした。どのように私は同じ文字列から複数の6桁の数字を取得するためにこれを編集するのですか?VBAを使用してテキスト文字列内に複数の6桁の数字を抽出する方法

Function SixDigit(S As String, Optional index As Long = 0) As String 
    Dim RE As Object 
Set RE = CreateObject("vbscript.regexp") 
With RE 
    .Pattern = "(?:\b|\D)(\d{6})(?:\b|\D)" 
    .Global = True 
     SixDigit = .Execute(S)(index).submatches(0) 
End With 
End Function 

答えて

0

以下のコードを使用し、ソース:

https://msdn.microsoft.com/en-us/library/tdte5kwf(v=vs.84)

Function RegExpTest(patrn, strng) 
Dim regEx, Match, Matches, s 

' Create the regular expression. 
Set regEx = New RegExp 
regEx.Pattern = patrn 
regEx.IgnoreCase = True 
regEx.Global = True 

' Do the search. 
Set Matches = regEx.Execute(strng) 

' Iterate through the Matches collection. 
s = "" 
For Each Match in Matches 
    s = s & "Match found at position " 
    s = s & Match.FirstIndex & ". " 
    s = s & "Match Value is '" 
    s = s & Match.Value & "'." 
    s = s & vbCRLF 
Next 

RegExpTest = s 
End Function 
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4")) 
関連する問題