Page 1 of 1

Replacing text case inside the parentheses

PostPosted: Wed Mar 03, 2021 12:14 pm
by kacharava
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

Re: Replacing text case inside the parentheses

PostPosted: Wed Mar 03, 2021 2:00 pm
by Luuk
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.

Re: Replacing text case inside the parentheses

PostPosted: Wed Mar 03, 2021 3:07 pm
by Luuk
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

Re: Replacing text case inside the parentheses

PostPosted: Wed Mar 03, 2021 7:08 pm
by kacharava
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.

Re: Replacing text case inside the parentheses

PostPosted: Wed Mar 03, 2021 7:13 pm
by kacharava
"?" 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 "?".

Re: Replacing text case inside the parentheses

PostPosted: Thu Mar 04, 2021 12:19 am
by Admin
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

Re: Replacing text case inside the parentheses

PostPosted: Thu Mar 04, 2021 5:36 am
by Luuk
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)»

Re: Replacing text case inside the parentheses

PostPosted: Thu Mar 04, 2021 6:40 am
by Admin
I am seeing this issue with "«" or "»" characters and others, I will check in the source code.

Re: Replacing text case inside the parentheses

PostPosted: Fri Mar 12, 2021 4:46 am
by Admin
Hi, this is an issue with \U \L \E and characters that are not ASCII... it does not work properly atm, unfortunately.

Re: Replacing text case inside the parentheses

PostPosted: Mon Mar 22, 2021 11:25 am
by kacharava
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.