Sub ChapII_A_2_b_V1()
' Cocher : Menu Outils > Reférences > Microsoft VBScript Regular Expressions
' II-A-2-b
Dim Chaine As String
Chaine = Cells(22, 2)
'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
Set reg = CreateObject("VBScript.RegExp")
reg.Pattern = "(\d.*\d[\%])" '"(\s\d\s)(\d?\d[^\w\.@-])" / reg.Pattern = "[B]^[/B](\d.*\d[\%])\s"
' Paramétrage :
reg.MultiLine = False ' ............ Active ou non la recherche sur plusieurs lignes à la fois.
reg.IgnoreCase = False ' ........... Précise si la recherche est sensible ou non à la casse (majuscules/minuscules).
reg.Global = True ' ................ Précise si la recherche porte sur la première occurence ou sur toutes.
' Test si pattern Trouvé
MsgBox reg.Test(Chaine)
' Progamme
Set Matches = reg.Execute(Chaine) ' reg.Execute("capacité")
reg.Pattern = "(\d{4})"
Set Matches = reg.Execute(Chaine)
For Each Match In Matches
Debug.Print "source >>", Match.Value
MsgBox "source >> " & Match.Value
For i = 0 To Match.SubMatches.Count - 1
Debug.Print "[$" & i + 1 & "]", Match.SubMatches(i)
MsgBox "[$" & i + 1 & "] " & Match.SubMatches(i)
Next i
Next Match
' libération d'objets
Set Matches = Nothing
Set Match = Nothing
Set reg = Nothing
End Sub