Since it took me a while to figure the correct syntax for my rename job, I thought I share it with you.
I had a couple of files named:
001.jpg
002.jpg
.
.
056.jpg
and I wanted just to insert some descriptive text at the beginning of the name, but keep the numbers as they were.
Here's the RegExp solution to do the job:
(to be entered in the "Rename special" "RegExp Rename")
(^\d{3}) > My_descriptive_text_$1
Explanation:
^ = Search at the beginning of the input string
\d = Search for digits
{3} = Search for exactly 3 digits
(...) = Capture the match for reuse
$1 = Reuse the captured match
Result:
My_descriptive_text_001.jpg
My_descriptive_text_002.jpg
.
.
My_descriptive_text_056.jpg
You see, it's worth to spend some time learning RegExp syntax, maybe for more sophisticated solutions.
Rename special with RegExp
Rename special with RegExp
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
-
- Site Admin
- Posts: 60597
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Rename special with RegExp
Thanx, Ralph!
But wouldn't it have been easier to simply keep the last 7 chars of the names? Then you could even do:
Old_descriptive_text_001.jpg
Old_descriptive_text_002.jpg
...
New_descriptive_text_001.jpg
New_descriptive_text_002.jpg
...
by
(last 7 chars) > New_descriptive_text_$1
only: I don't know how to do "last 7 chars" in RegExp, do you?
EDIT: I think I got it: (.*)(.{7}$) > New_descriptive_text_$2
This will place "New_descriptive_text_" in front of the last 7 chars and drop everything that was before them. If the name is smaller than 7 chars it won't be changed at all. Test carefully, I'm not an expert in this!
But wouldn't it have been easier to simply keep the last 7 chars of the names? Then you could even do:
Old_descriptive_text_001.jpg
Old_descriptive_text_002.jpg
...
New_descriptive_text_001.jpg
New_descriptive_text_002.jpg
...
by
(last 7 chars) > New_descriptive_text_$1
only: I don't know how to do "last 7 chars" in RegExp, do you?
EDIT: I think I got it: (.*)(.{7}$) > New_descriptive_text_$2
This will place "New_descriptive_text_" in front of the last 7 chars and drop everything that was before them. If the name is smaller than 7 chars it won't be changed at all. Test carefully, I'm not an expert in this!
-
- Site Admin
- Posts: 60597
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
There's a lot in the web. This is nice: http://www.regular-expressions.info/frew wrote:How did you learn how to do regular expression work?
Re: Rename special with RegExp
Will test it soon.admin wrote: EDIT: I think I got it: (.*)(.{7}$) > New_descriptive_text_$2
This will place "New_descriptive_text_" in front of the last 7 chars and drop everything that was before them. If the name is smaller than 7 chars it won't be changed at all. Test carefully, I'm not an expert in this!
Probably just a different way to do almost the same.
Sharing this solution in the forum came to my mind primarly because it took me a while to figure, how to reuse the stored match.
(Apparently the \1...\n syntax - as described at the RegExp link from within the TV3 help - doesn't work here)
Thanks anyway, will keep you posted.
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)