Move a string containing digits_digits to start of filename

A swapping-ground for Regular Expression syntax

Move a string containing digits_digits to start of filename

Postby w945106 » Thu Jul 04, 2024 10:14 pm

How do I move "digits_digits" to the start of a filename?
There are many variations of the following:

Name: Volcano_NP_200606_0325_NIX.jpg

New Name: 200606_0325_Volcano_NP_NIX.jpg

Name: Steamboat_200512_001_NIX.jpg

New Name: 200512_001_Steamboat_NIX.jpg

I can clean up the leading underscores e.g. "_200606" or double underscores e.g. "__" later if that makes the expression simpler.

Thanks.
w945106
 
Posts: 4
Joined: Mon Aug 29, 2022 9:07 pm

Move "date_digits_" to beginning

Postby Luuk » Fri Jul 05, 2024 2:12 am

For the examples, can use a Match and Replace something like...
^(.+_)(20\d{4}_\d+_)(.+)
\2\1\3
Luuk
 
Posts: 803
Joined: Fri Feb 21, 2020 10:58 pm

Re: Move a string containing digits_digits to start of filename

Postby w945106 » Sat Jul 06, 2024 6:48 pm

Luuk,

Thank you. That worked with a couple variations.

For the examples, can use a Match and Replace something like...
^(.+_)(20\d{4}_\d+_)(.+)
\2\1\3

This worked to rename about half:
^(.+_)(\d+_\d+_)(.+)
\2\1\3

And this another quarter:
^(.+_)(\d+_\d+_?)(.+)
\2_\1\3

The rest I can do manually.
w945106
 
Posts: 4
Joined: Mon Aug 29, 2022 9:07 pm


Return to Regular Expressions