Regex: Problem Replace by: $1\L$2 (Capitalize words)

Tool for Search and Replace across multiple files.
Post Reply
me_suzy
Posts: 20
Joined: Thu Jul 14, 2016 11:31 am

Regex: Problem Replace by: $1\L$2 (Capitalize words)

Post by me_suzy »

hello. I have this regex that doesn't work:

Lowercase letters within words (e.g. LowerCASe => Lowercase)
Find: (\w)([A-Z]+)
Replace: $1\L$2

The problem is at replace. $1\L$2 does't work. Ii replace all the words with \L
User avatar
DigitalVolcano
Site Admin
Posts: 1717
Joined: Thu Jun 09, 2011 10:04 am

Re: Regex: Problem Replace by: $1\L$2 (Capitalize words)

Post by DigitalVolcano »

It doesn't support case switches in the replace text.

If you look to the right of the replace box there are options in the drop-down list to replace with upper, lower and title case if this helps.
ebulerdo
Posts: 18
Joined: Mon Dec 09, 2013 8:54 am

Re: Regex: Problem Replace by: $1\L$2 (Capitalize words)

Post by ebulerdo »

Some years have passed since this was posted. I am exactly in the same situation as the OP. It would be very useful to support \L$ or whatever code to change case in replacements.

Can this be added to the wishlist for v4, please?
User avatar
DigitalVolcano
Site Admin
Posts: 1717
Joined: Thu Jun 09, 2011 10:04 am

Re: Regex: Problem Replace by: $1\L$2 (Capitalize words)

Post by DigitalVolcano »

Isn't the case replace setting suitable (to the right of the replace box), or do you need more control over the individual capture groups?
ebulerdo
Posts: 18
Joined: Mon Dec 09, 2013 8:54 am

Re: Regex: Problem Replace by: $1\L$2 (Capitalize words)

Post by ebulerdo »

The case replace setting is helpful when you want to apply that change to the whole replacement string. It would be very useful to be able to change case of the capture group only, though. In the regex flavor I use this is done with \u1 or \l1. It seems in the flavor the OP uses it's L$1. Any way would be ok for me.

In this particular case I am working on, I need to reuse some file extensions (jpg, pdf, tif) in uppercase (JPG, PDF, TIF) in a different part of the string. Right now I'm working around it by using a mark before the text (¬jpg, ¬pdf) then running a separate replacement for every extension (replace ¬jpg with JPG). But it would be much more concise and agile if it could all be handled with only one replacement.

Thanks for considering this.
Post Reply