Sublime Forum

Upper case with replace

#1

Hi all,

When using find and replace with regex, is it possible to replace text with capitalized letters of the matching text?

Thanks!

0 Likes

#2

There might be a way via regex but I don’t know it off the top of my head.

However if you already have the text selected, you can convert to uppercase via the menu Edit > Convert Case > Upper Case (also available from the Command Palette).

2 Likes

#3

A \U in front of a capture in the regex replacement will replace the text with an upper case version, and \L will lower case it.

For example, if you search Lorem and replace with \U$0, that would indicate that the whole of the matched text (represented by $0) should be replaced uppercase.

You can also do that with more regular captures, such as \bl(\w+) and a replacement of L\U$1 if you wanted to find all words starting with a lower case l and replace them with all uppercase equivalents, etc.

0 Likes

#4

Thank you, @OdatNurd! I was using \U$1 in the replace field, but forgot the parentheses in the search field. Thank you very much!

0 Likes