Thread: [Solved] Regex-pattern
View Single Post
 
Old 12-30-2024, 03:13 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,384
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why not use Word's wildcard Find method, for which you could have:
Find = , [A-Z][a-z]@ [A-Z][a-z]@,
This ensures you'll only find a comma, followed by a space, then a proper-case word, followed by a space, then another proper-case word, followed by a comma.

A macro equivalent to italicize all such text (since I don't know what you want to do with what you find) would be:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Replacement.Font.Italic = True
    .Text = ", [A-Z][a-z]@ [A-Z][a-z]@,"
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]