Mass rename files with Regex

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
jannn
Junior Member
Junior Member
Posts: 3
Joined: 2020-09-29, 09:48 UTC

Mass rename files with Regex

Post by *jannn »

Hello, I wish to rename files, I have success but some names are cut of 2 last same characters (BB, CC or GG). What is bad in my command please?
Image: http://www.onweb.cz/regex.jpg
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Mass rename files with Regex

Post by *Stefan2 »

Hi and welcome.

Because you have told TC to remove doubled parts (BB, CC or GG) with your expression: (.*)\1

That more complicate expression is not need at all for your issue and TCs regex engine, just use only -.+
And it would be fine to post the names and the expression additionally as text here too, so others can use that for testing what's going on.




 
jannn
Junior Member
Junior Member
Posts: 3
Joined: 2020-09-29, 09:48 UTC

Re: Mass rename files with Regex

Post by *jannn »

I would like to rename (cut) file name just to first dash. I use command (.*)\1-(.*)
It works fine for names like PH0609_BE-EYESHADOW-LUMIERE-BLUE-EMERALD.jpg but not for PH0609_BB-EYESHADOW-LUMIERE-BLAZING-BLUE.jpg
result (bad): PH0609_.jpg
correct result: PH0609_BB.jpg
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Mass rename files with Regex

Post by *Stefan2 »

Yes, as I wrote
Stefan2 wrote: 2020-09-29, 11:08 UTC ... just use only -.+

FROM:
PH0609_BE-EYESHADOW-LUMIERE-BLUE-EMERALD.jpg
PH0609_BB-EYESHADOW-LUMIERE-BLAZING-BLUE.jpg
TO:
PH0609_BE.jpg
PH0609_BB.jpg

USE MRT (multi rename tool):
Search : -.+
Replace:<Clear>
[_]E
[x]RegEx


Explanation:
-.+ >>>>> match anything one-ore-more times from first hyphen greedy to the end





You have shown in your linked picture:

FROM:
PH0609_BE-EYESHADOW-LUMIERE-BLUE-EMERALD.jpg
PH0609_BB-EYESHADOW-LUMIERE-BLAZING-BLUE.jpg
TO:
PH0609_BE.jpg
PH0609_.jpg

Search : (.*)\1-(.*)
Replace:<Clear>
[_]E
[x]RegEx

Explanation:
(.*)- >>>>> match anything until an hyphen
(.*)\1- >>> match anything which arise twice (doubled like "BB") until an hyphen
(.*)\1-(.*)> match anything which arise twice until an hyphen and then greedy the rest

And you have used the star-multiplicator * which means none-or-more occurrences.
So if (.*) match nothing and \1 means double "those nothing", it is just ignored.


 
jannn
Junior Member
Junior Member
Posts: 3
Joined: 2020-09-29, 09:48 UTC

Re: Mass rename files with Regex

Post by *jannn »

Thank you very much for help.
Post Reply