Bonjour à tous
Je dois récupérer des infos d'un fichier PDF et j'utilise l'objet RegEx pour ne faire qu'une seule passe
Prenons l'exemple suivant
Avec le pattern suivantTest
Test Number 000 fgkfdkgldj dsfhskdfh fdsqkfhdsk
Test
Length: 65
Type: Numerical, Special
Just: N/A
Dec place: N/A
j'obtiens le résultat suivant(Test Number\s)(\w{3}\s)(\w.*)(.*\n)(.*\n)(Length:\s)(\d*)(\n)(Type:\s)(\w.*)(\n)(Just:\s)(\w.*)(\n)(Dec place:\s)(\w.*)
Donc jusque là content mais l'implémentation VBA je deviens
Mon code
avec
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 Private Function fGetRegEx(psInput As String, psPattern As String, Optional GlobalSearch As Boolean = True, _ Optional MultiLine As Boolean = False, Optional IgnoreCase As Boolean = True) As MatchCollection Dim mcolResults As MatchCollection Dim objRegEx As New RegExp Dim sInput As String If psInput = vbNullString Or psPattern = vbNullString Then GoTo Exit_ 'psInput = Replace(psInput, Chr(13), vbNewLine) '-------> Sans résultat 'MultiLine = True ------------------------------------------> Sans résultat With objRegEx .Global = GlobalSearch .MultiLine = MultiLine .IgnoreCase = IgnoreCase .Pattern = psPattern End With If objRegEx.Test(psInput) Then Set mcolResults = objRegEx.Execute(psInput) Set fGetRegEx = mcolResults End If Exit_: Exit Function End Function
Merci par avance pour tout aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 Public Function fGetValueRegEx(Optional psValue As String) Dim oMatches As MatchCollection, oMatch As Match, oSubMatch As Variant Dim sValue As String, sPattern As String sPattern = "(Test Number\s)(\w{3}\s)(\w.*)(.*\n)(.*\n)(Length:\s)(\d*)(\n)(Type:\s)(\w.*)(\n)(Just:\s)(\w.*)(\n)(Dec place:\s)(\w.*)" Debug.Print Chr(13) & psValue Set oMatches = fGetRegEx(psValue, sPattern) If oMatches Is Nothing Then GoTo Exit_ For Each oMatch In oMatches If oMatch.Value = "" Then GoTo Exit_ '-----------> toujours Vrai :aie: Debug.Print oMatch.Value Next oMatch Exit_: Set oSht = Nothing Set oRg = Nothing Set oMatches = Nothing End Function
Partager