Thread: [Solved] Regex-pattern
View Single Post
 
Old 12-31-2024, 04:01 AM
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

Quote:
Originally Posted by mstde View Post
@macropod: in my example the name consisted of just two words, but there can be other variants, too:
..

Would your method find these variants, too?
No, it wouldn't, because it was written to exclude anything other than the two-word kind of example you specified.

If you want something that will catch all the examples you have now given, you could use:
Find =, [A-Z][!,]@ [A-Z][!,]@,

This will capture all instances of a comma, followed by a space, then a proper-case word, any number of characters other than a comma, finally a space and another proper-case word (hyphenated or otherwise) before a comma.

Again, the macro equivalent to italicize all such text (since I still 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][!,]@,"
    .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]