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.


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


bottom of page