2015-06-30 76 views
0

基本上我一直在閱讀this。我試圖找到的是如何在一個組中提取模式的特定部分。無法找到VBScript_Regex_55上的文檔

例如,假設我想要查找電子郵件的模式如下,並且我想要使用以下模式專門檢索電子郵件的域:([\w.-]+)@([\w.-]+.\w+)

我知道我可以在第一組模式中使用lookahead,但是之後在'@'之前檢索電子郵件的一部分,我需要重新編寫相同的代碼,這不是非常乾燥。

+0

http://www.regular-expressions.info/brackets.html和測試它與https://regex101.com/ –

回答

1

對不起,該教程是法語:http://cafeine.developpez.com/access/tutoriel/regexp/
測試此片的代碼中,我過去從這個鏈接:

Sub testRegEx() 
Dim reg As VBScript_RegExp_55.regexp 
Dim Match As VBScript_RegExp_55.Match 
Dim Matches As VBScript_RegExp_55.MatchCollection 

' instanciation 
Set reg = New VBScript_RegExp_55.regexp 

reg.Pattern = "([\w.-]+)@([\w.-]+.\w+)" 
Set Matches = reg.Execute("[email protected]") 
For Each Match In Matches 
    Debug.Print "source >>", Match.Value 
    For i = 0 To Match.SubMatches.Count - 1 
     Debug.Print "[$" & i + 1 & "]", Match.SubMatches(i) 
    Next i 
Next Match 
End Sub 
+0

謝謝scraaappy 換句話說,如果我正確理解這個'SubMatches'集合具有所有組。 – sgp667