Quote:
Originally Posted by gmaxey
Batman1,
Thanks for the post. I see that your suggested pattern "requires" two or more words between the commas to return a match. So
, John, won't match but
, John smith, would.
|
If you read post #1, #2, #3, #4 you will understand why I wrote: Last name-first name with 2, 3, 4 ... parts, so there should be at least 2 parts.
Quote:
A RegEx pattern master I am not. I wonder if it is possible to construct the pattern such that the last word (the word before the ending comma) must be captitalized e.g.,
,Gerd van Ackerman, matches
,Gerd van ackeramn, would not
|
With my code ",Gerd van Ackerman," does NOT match. After the first comma there MUST be a space. This is a requirement of this thread.
The following code meets your requirements. I can't write a simpler pattern.
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-Z][^,]+)?,"
End With
Set Matches = RegEx.Execute(ActiveDocument.Range.text)
For Each Match In Matches
Debug.Print Match.Value
Next
End Sub