top of page

Regex to change case of letters

Note that you can easily use a regular expression search to capitalize certain strings in text. In this example we have a list of names, and we want to capitalize the last names of each person. Using NotePad++, we target strings with a first initial and then a period and a space ([A-Z]{1}\. ) and then in the second group any word containing uppercase or lowercase letters of any length ([A-Za-z]*). For search group # 1 enclosed in parentheses, the letter range is listed in the brackets, and then the letter count for the word is given in braces {}. We escape the period with a backward slash because a period has a separate meaning in regex. For the second group, we search for any uppercase or lowercase letter, with the asterisk signifying any number of characters.


([A-Z]\. )([A-Za-z]*)


In the replace field we can then reference the first group and the second group as \1 and \2. Adding \u before the second group signifier will capitalize the first letter.


\1\u\2




Switching \u to \l will make the first letter of the word in the second group lowercase.


Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page