Replacing text case inside the parentheses

Bulk Rename Utility How-To's

Replacing text case inside the parentheses

Postby kacharava » Wed Mar 03, 2021 12:14 pm

Hi,

I need to rename a huge bunch of filenames like Outside Parentheses (InSIDe ParenTHeses).ext to Outside Parentheses (inside parentheses).ext.

I.e. I need to leave every letter outside parentheses intact while make all letters inside parentheses small.

How can I achieve that with BRU?

Thanks
kacharava
 
Posts: 4
Joined: Wed Mar 03, 2021 11:53 am

Re: Replacing text case inside the parentheses

Postby Luuk » Wed Mar 03, 2021 2:00 pm

Inside Regex(1) to put checkmark in "v2", then the "Match" and "Replace" can be like ...
(\(.*?\))/g
\L$1

The "\L" is conducting "lowercase" inside the parentheses.
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Replacing text case inside the parentheses

Postby Luuk » Wed Mar 03, 2021 3:07 pm

The first Match is using "/g" to conduct "all" of the parentheses, so renaming like ...
AA (BB) CC (DD) EE (FF).txt ===> AA (bb) CC (dd) EE (ff).txt

To conduct parentheses only at ending of names, its to be (\([^)]*\))$ so instead renaming like ...
AA (BB) CC (DD) EE (FF).txt ===> AA (BB) CC (DD) EE (ff).txt
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Replacing text case inside the parentheses

Postby kacharava » Wed Mar 03, 2021 7:08 pm

Thanks a lot! It works!

Except... this regexp for some yet unknown reason replaces "«" and "»" to "?".

Anyway I would better replace ? back with « or » once than rename 1500 files manually.
kacharava
 
Posts: 4
Joined: Wed Mar 03, 2021 11:53 am

Re: Replacing text case inside the parentheses

Postby kacharava » Wed Mar 03, 2021 7:13 pm

"?" originally was a sign with the white question mark put into a black rhombus. May be this forum can't accept this sign.

kacharava wrote:replaces "«" and "»" to "?".
kacharava
 
Posts: 4
Joined: Wed Mar 03, 2021 11:53 am

Re: Replacing text case inside the parentheses

Postby Admin » Thu Mar 04, 2021 12:19 am

You can also do this using "Simple" regex.

Enable Simple in RegEx(1)

Then
Match : %1(%2)
Replace: %1(\L%2)

\L means lowercase the rest of the text

Make sure you are using the latest version 3.4.2.0 or newer
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replacing text case inside the parentheses

Postby Luuk » Thu Mar 04, 2021 5:36 am

This very good to know about "Simple" also granting case conversions, because its much easier for the eyesight!

During the experiments, it seems that RegEx(1) fails whenever trying to lowercase the "«" or "»" characters.
It must consider them both uppercases, because the \U conversion does always succeed with both of them.
But its strange, because why two characters getting assigned to the same lowercase conversion?
So then testing with more unicodes, it seem that "rhombus/question" is some "default character" for "unknown".

This another way:.. Convert "«" into "<" and "«" into "<"... Then lowercase... Then convert them back...
So this is needing five different Match/Replace, each being separated by (?X) like ...
«/g(?X)»/g(?X)(\(.*?\))/g(?X)</g(?X)>/g
<(?X)>(?X)\L$1(?X)«(?X)»

But if lowercasing only at the very (End Of Name), it would instead be like ...
«/g(?X)»/g(?X)(\([^)]*\))$(?X)</g(?X)>/g
<(?X)>(?X)\L$1(?X)«(?X)»
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Replacing text case inside the parentheses

Postby Admin » Thu Mar 04, 2021 6:40 am

I am seeing this issue with "«" or "»" characters and others, I will check in the source code.
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replacing text case inside the parentheses

Postby Admin » Fri Mar 12, 2021 4:46 am

Hi, this is an issue with \U \L \E and characters that are not ASCII... it does not work properly atm, unfortunately.
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replacing text case inside the parentheses

Postby kacharava » Mon Mar 22, 2021 11:25 am

Thank you for checking this out.

Admin wrote:Hi, this is an issue with \U \L \E and characters that are not ASCII... it does not work properly atm, unfortunately.
kacharava
 
Posts: 4
Joined: Wed Mar 03, 2021 11:53 am


Return to How-To