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
RegExp batch rename
Re: RegExp batch rename
There are dozen of ways to do this. Why does it matter if it works?
(?:\()(\d)(?:\)) > (0$1)One of my scripts helped you out? Please donate via Paypal
-
pixelsearch
- Posts: 43
- Joined: 21 May 2018 18:45
Re: RegExp batch rename
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...
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
A
And you can reduce your set for files / paths to 9.
# is not a regex metacharacterAnd 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)One of my scripts helped you out? Please donate via Paypal
-
pixelsearch
- Posts: 43
- Joined: 21 May 2018 18:45
Re: RegExp batch rename
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)
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
Mode modifiers in VB6? They aren't supported^^
One of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club