Multi rename: copy regex'ed part of filename

English support forum

Moderators: white, sheep, Hacker, Stefan2

Post Reply
lupida
Junior Member
Junior Member
Posts: 15
Joined: 2008-06-02, 17:31 UTC

Multi rename: copy regex'ed part of filename

Post by *lupida » 2018-10-09, 13:14 UTC

Hi,

I have filenames of this pattern

Code: Select all

SOMERANDOMTEXTOFVARYINGLENGTH_1118527979_dat20181007_id23654242364.pdf
I would like to copy the encoded date after "_dat" in front of the whole filename, so that I get

Code: Select all

2018-10-07_SOMERANDOMTEXTOFVARYINGLENGTH_1118527979_dat20181007_id23654242364.pdf
I figured out how to generate three match groups with regex:

Code: Select all

(?<=_dat)(\d{4})(\d{2})(\d{2})
(see it live here http://rubular.com/r/eQdqAoAlr0) but I cannot figure out how to translate this into TC Multi rename tool.

Any hint is appreciated!

Lupida

User avatar
Stefan2
Power Member
Power Member
Posts: 2170
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Multi rename: copy regex'ed part of filename

Post by *Stefan2 » 2018-10-09, 13:42 UTC

FROM:
SOMERANDOMTEXTOFVARYINGLENGTH_1118527979_dat20181007_id23654242364.pdf
TO:
2018-10-07_SOMERANDOMTEXTOFVARYINGLENGTH_1118527979_dat20181007_id23654242364.pdf

RULE:
match date after "-dat", reformat and move to front.


MUT
Search: (.+_dat)(\d\d\d\d)(\d\d)(\d\d)
Replace: $2-$3-$4_$1$2$3$4
[x]Regex



Note:
any remaining part after the match, as here e.g. "_id23654242364.pdf", is ignored by TC engine on this example and so we didn't need to take care on this.

 

lupida
Junior Member
Junior Member
Posts: 15
Joined: 2008-06-02, 17:31 UTC

Re: Multi rename: copy regex'ed part of filename

Post by *lupida » 2018-10-09, 14:01 UTC

Whow, thanks a thousand! Works like a charm.
Seems I was thinking in too complicated ways, trying to use "Subst." but then not being able to figure out how to capture the entire rest of the string.

Post Reply