Remove date from file name

A swapping-ground for Regular Expression syntax

Remove date from file name

Postby r.pruim » Wed Sep 20, 2023 10:44 am

Trying to rename a file, to remove a date but so far unsuccessfull, anyone can share an RegEx to remove dates en the _

For example I want to remove dates and the _ in the data from files called

NL_XXX_XXX_20210804

So it should become

NL_XXX_XXX
r.pruim
 
Posts: 3
Joined: Wed Sep 20, 2023 10:39 am

Re: Remove date

Postby r.pruim » Wed Sep 20, 2023 11:03 am

Nevermind already found out, if anyone else need I used below

_\d{4}\d{1,2}\d{1,2}

\1
r.pruim
 
Posts: 3
Joined: Wed Sep 20, 2023 10:39 am

Remove ending dates like _YYYYMMDD

Postby Luuk » Wed Sep 20, 2023 3:27 pm

Since nothing is (grouped) inside of the "Match", the posted answer needs a checkmark inside for "v2".
But remember, it removes "_" followed by any 6-thru-8 digits, from anywhere inside of the filenames.
To only remove dates like _YYYYMMDD from the very end, can use a "Match" and "Replace" like...
(.+)_(19|20)\d{6}$
\1

Or to remove ending dates like either _YYYYMD or _YYYYMMDD...
(.+)_(19|20)\d{4,6}$
\1
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm


Return to Regular Expressions


cron