RegEx challenge: replace dash by space, but not on the date

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
CSchneider
Junior Member
Junior Member
Posts: 4
Joined: 2024-02-29, 20:19 UTC

RegEx challenge: replace dash by space, but not on the date

Post by *CSchneider »

Hello,

we have many files in the following format (created by an Adobe software):

WE-TEST-IT-2021-01-13-Test-2019-available.jpg
WE-TEST-IT-2022-01-14-Test-Extensions-Promotion.jpg
WE-TEST-IT-2023-01-15-Test-Extensions-Webinar.jpg
WE-TEST-IT-2024-02-26-Test-added-to-Software-Portfolio.jpg
WE-TEST-IT-2024-02-27-Test-Studio-advancing-resilience.jpg
WE-TEST-IT-2024-02-28-Test-One-2024-1-available.jpg
WE-TEST-IT-2024-02-29-Test-added-to-Software-Portfolio.jpg

I am looking for a RegEx expression for the Multi Rename Tool to replace all dashes by spaces, except for those in the ISO date YYYY-MM-DD within the filenames.

The outcome should then be:

WE TEST IT 2021-01-13 Test 2019 available.jpg
WE TEST IT 2022-01-14 Test Extensions Promotion.jpg
WE TEST IT 2023-01-15 Test ExtensionsWebinar.jpg
WE TEST IT 2024-02-26 Test added to Software Portfolio.jpg
WE TEST IT 2024-02-27 Test Studio advancing resilience.jpg
WE TEST IT 2024-02-28 Test One 2024 1 available.jpg
WE TEST IT 2024-02-29 Test added to Software Portfolio.jpg

The rules are explained in the helpfile with the following limitation:
The used regex library has a limitation that look ahead must be at the end of the regular expression and look behind must be at the start. Otherwise an error will be shown.

I have spent hours trying it and even with Copilot, but it seems that it simply does not work or runs into this error.

Could you please help me finding a RegEx that works in Total Commander, please?
User avatar
Dalai
Power Member
Power Member
Posts: 9393
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: RegEx challenge

Post by *Dalai »

The following should work although it's a two-step process. No idea if this is possible in a single rename operation.

Search for:

Code: Select all

-
Replace with:

Code: Select all

 
(single space character)

Then reload the list via the button with the arrow on it (left of the "Start" button), or press F5.

Search for:

Code: Select all

(.+)(\d{4})\s(\d{2})\s(\d{2})(.+)
Replace with:

Code: Select all

$1$2-$3-$4$5
[X] RegEx

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
CSchneider
Junior Member
Junior Member
Posts: 4
Joined: 2024-02-29, 20:19 UTC

Re: RegEx challenge

Post by *CSchneider »

Hi Dalai,

thank you very much for your idea with the two steps - that is a nice workaround and highly appreciated if there is not the one-step-solution I was looking for.
User avatar
white
Power Member
Power Member
Posts: 4623
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: RegEx challenge

Post by *white »

Code: Select all

Search for:   [-(\d\d\d\d-\d\d-\d\d)?]
Replace with: [ $1]
CSchneider
Junior Member
Junior Member
Posts: 4
Joined: 2024-02-29, 20:19 UTC

Re: RegEx challenge

Post by *CSchneider »

white wrote: 2024-03-01, 09:41 UTC

Code: Select all

Search for:   [-(\d\d\d\d-\d\d-\d\d)?]
Replace with: [ $1]
Hi white,

thank you for the idea, unfortunately is removes the date and also the other numbers:

WE TEST IT Test available.jpg
WE TEST IT Test Extensions Promotion.jpg
WE TEST IT Test ExtensionsWebinar.jpg
WE TEST IT Test added to Software Portfolio.jpg
WE TEST IT Test Studio advancing resilience.jpg
WE TEST IT Test One available.jpg
WE TEST IT Test added to Software Portfolio.jpg
User avatar
white
Power Member
Power Member
Posts: 4623
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: RegEx challenge

Post by *white »

CSchneider wrote: 2024-03-01, 20:07 UTC thank you for the idea, unfortunately is removes the date and also the other numbers:
Don't include the outer brackets [ ].
User avatar
beb
Senior Member
Senior Member
Posts: 435
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: RegEx challenge: replace dash by space, but not on the date

Post by *beb »

Can be simplified like this:
Search for:

Code: Select all

-(\d+-\d+-\d+)?
Replace with:

Code: Select all

 $1
Results:
Image: https://i.imgur.com/ka8CalV.png
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
CSchneider
Junior Member
Junior Member
Posts: 4
Joined: 2024-02-29, 20:19 UTC

Re: RegEx challenge: replace dash by space, but not on the date

Post by *CSchneider »

Hi white and beb - thank you very much for your solutions that work both very well. Highly appreciated - you made my day!
Post Reply