Thread: [Solved] Regex-pattern
View Single Post
 
Old 01-02-2025, 12:59 PM
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 gmaxey View Post
Test, Joe Smith, and test, test.
or
Test, Bob Miller, and test, text.
It will not match any of the examples given in post #3.

For data structured as in the attached photo, the sample code is below
This is just an example. Everyone should make corrections for their needs
Code:
Sub ScratchMacro()
Dim RegEx As Object, Matches As Object, Match As Object
    Set RegEx = CreateObject("VBScript.RegExp")
    With RegEx
        .Global = True
        .Pattern = ", [A-Z][^, ]+( [A-Za-z][^,]+){1,},"
    End With
    Set Matches = RegEx.Execute(ActiveDocument.Range.Text)
    For Each Match In Matches
        Debug.Print Match.Value
    Next
End Sub
Attached Images
File Type: png regex.png (28.9 KB, 25 views)