Skip to main content
Participant
August 3, 2023
Answered

Grep Last Name to Initials

  • August 3, 2023
  • 1 reply
  • 287 views

Hi,

 

I have a document with names interspersed throughout. Client just decided they only want the last initial included. Is there a grep search that could replace the last word (some people have a middle name included, some don't) of a line with the first letter of that word and a period after it?

 

So John Smith would become John S. and Michael Andrew Franklin would become Michael Andrew F.

 

Any help would be amazing!

This topic has been closed for replies.
Correct answer brian_p_dts

You can try this: 
F: ((\u\l+ )+)(\u)\l+

C: $1$3.

 

Of course, this would also catch other proper names that are are two or more words. 

 

Maybe someone has a better way to catch names that have punctuation in them, ie. Mary-Anne Smith. 

 

1 reply

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
August 3, 2023

You can try this: 
F: ((\u\l+ )+)(\u)\l+

C: $1$3.

 

Of course, this would also catch other proper names that are are two or more words. 

 

Maybe someone has a better way to catch names that have punctuation in them, ie. Mary-Anne Smith. 

 

SHSBKAuthor
Participant
August 3, 2023

COOLEST THING EVER!!! Thank you so much, you're awesome!

brian_p_dts
Community Expert
Community Expert
August 3, 2023

No problem. Also note it would miss names that have capitalization in the middle of the name, ie. MaryAnne Smith. My GREP-fu is not the greatest. Others may have more robust searches.