Page 1 of 1

RegExp batch rename

Posted: 29 Aug 2022 15:32
by pixelsearch
Hi everybody
I got a folder containing the following files :

filename (1).txt
...
filename (9).txt
filename (10).txt
...
filename (19).txt

Using XYplorer, I wanted to batch rename some files so (1) to (9) become (01) to (09)
This is the menu option and the pattern I tried : File => Rename Special => RegExp Rename...
(.*\()(\d\)\..*) > $10$2

It seems to work and filename(1).txt became filename(01).txt ... filename(9).txt became filename(09).txt ... other files names remained untouched (as they already got 2 digits)

Could you please share your opinion about this, in case there is another way to do it ?
Thanks

Re: RegExp batch rename

Posted: 29 Aug 2022 16:27
by highend
There are dozen of ways to do this. Why does it matter if it works?
(?:\()(\d)(?:\)) > (0$1)

Re: RegExp batch rename

Posted: 29 Aug 2022 17:22
by pixelsearch
Thanks highend for your input.
As it took me time to find the RegExp solution, I was asking in case there was a simpler option in another XPlorer Rename menu, without RegExp.

Anyway as it works fine, I'm gonna keep those patterns carefully because this specific batch Rename is needed from time to time. Gonna add them in a reminder file I already got, named "RegEx characters to be escaped (13).txt", which contains the following lines (I had to open that file before trying and finding the RegExp solution, as I'm a newbie when it comes to RegExp) :

\.^$|[({*+?#)
Above are the 13 RegEx metacharacters to be escaped, for example :
a dot . will be escaped to \.
a star * will be escaped to \*
etc...

Re: RegExp batch rename

Posted: 29 Aug 2022 19:42
by highend
A # is not a regex metacharacter

And you can reduce your set for files / paths to 9.
|, ? and * can't be a (officially) part of them (at least not under NTFS filesystems)

Re: RegExp batch rename

Posted: 30 Aug 2022 11:30
by pixelsearch
Hi highend
Thanks for the clarification. Just a question :
If # isn't a regex metacharacter, why does it need to be escaped in the following test ?

Match text:
#abcde

Search pattern:
(?x)# introduces a comment, next # must be escaped
\#abc

Result:
#abc

Without escaping it, the result is wrong. Maybe # should be considered as a metacharacter as soon as we're dealing with eXtended (?x)

Re: RegExp batch rename

Posted: 30 Aug 2022 11:37
by highend
Mode modifiers in VB6? They aren't supported^^