Thread: [Solved] Regex-pattern
View Single Post
 
Old 01-05-2025, 11:41 AM
batman1 batman1 is offline Windows 11 Office 2013
Advanced Beginner
 
Join Date: Jan 2025
Posts: 57
batman1 is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Yes, Batman1, you are right! Sorry for my inattentive reading posts!
In fact, it doesn't have to be "|", and the code can be like this
Code:
Sub ScratchMacro()
Dim RegEx As Object, Matches As Object, Match As Object
    Set RegEx = CreateObject("VBScript.RegExp")
    With RegEx
        .Global = True
        .Pattern = ",( [A-Za-zü\-]+)* [A-Z][A-Za-zü\-]+,"
    End With

    Set Matches = RegEx.Execute(ActiveDocument.Range.text)
    For Each Match In Matches
        Debug.Print Match.Value
    Next
End Sub