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
Test
Test Number 000 fgkfdkgldj dsfhskdfh fdsqkfhdsk
Test
Length: 65
Type: Numerical, Special
Just: N/A
Dec place: N/A
Avec le pattern 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.*)
j'obtiens le résultat suivant
Nom : regExpMultilines.PNG
Affichages : 111
Taille : 51,3 Ko

Donc jusque là content mais l'implémentation VBA je deviens

Mon code

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
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
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
Merci par avance pour tout aide