Grep function changes "Name Surname" in "N. Surname"
I'm looking for Grep function that changes (in a list of 100 names and surnames) the name with the name initial pointed.
Example
Robert Redford >> R. Redford
Tom Cruise >> T. Cruise
Thank you!
I'm looking for Grep function that changes (in a list of 100 names and surnames) the name with the name initial pointed.
Example
Robert Redford >> R. Redford
Tom Cruise >> T. Cruise
Thank you!
Good! That makes it pretty simple!
There are various ways to do this, but I would go for replacing all lowercase characters that follow an uppercase and are followed by space, an uppercase and at least one lowercase, with a full stop.
Let's break that down:
all lowercase characters → \l+ (that's a lowercase 'ell', which stands for "lowercase")
.. that follow an uppercase → (?<=\u)\l+ (this is a lookbehind, which checks if there is an uppercase character immediately before what we just found)
.. and are followed by space, uppercase, lowercase → (?<=\u)\l+(?= \u\l) (which is a lookahead that verifies the space, uppercase, and lowercase)
If you use "find", you will see only the series of lowercase in the first name will be selected, and so all you need to replace it with is a single full stop itself.
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.