Flip 1st Part and 2nd Part of Filenames

A swapping-ground for Regular Expression syntax

Flip 1st Part and 2nd Part of Filenames

Postby tvrepairguy » Fri Jan 12, 2018 6:44 am

I am new to the BRU and need help with a specific issue. I have a bunch of image files which are pictures of artwork. The filename is composed of a Last Name, First Initial, then a number. The name is the artist and each number is a different piece or artwork. Some artists have multiple pieces. If the number is followed by _1,_2,_3, or _4 it is a different picture of the same piece of artwork. I need to move the numbers to the beginning of the filename for every single file. Here are examples of the 2 variations of the filenames as they are originally:

Khalil_A_I_12949509.jpg
King_Z_I_12801638.jpg
Kohn_L_I_12912185_1.jpg
Kohn_L_I_12912185_2.jpg
Kohn_L_I_12912185_3.jpg

I need the files to appear like this:

I_12949509_Khalil_A.jpg
I_12801638_King_Z.jpg
I_12912185_1_Kohn_L.jpg
I_12912185_2_Kohn_L.jpg
I_12912185_3_Kohn_L.jpg

An underscore is added between the number and last name and an underscore is deleted after the first initial. Does anyone know a RegEx command or anything that will automate this for me?

Thanks
tvrepairguy
 
Posts: 1
Joined: Fri Jan 12, 2018 6:08 am

Re: Flip 1st Part and 2nd Part of Filenames

Postby therube » Fri Jan 12, 2018 3:00 pm

1:RegEx
Code: Select all
Match:  ^([A-Z][a-z]*)_(.){1}_(.*)
Replace:  \3_\1_\2
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions