Regex help: move a string within filename

A swapping-ground for Regular Expression syntax

Regex help: move a string within filename

Postby jackson000 » Sun Oct 18, 2020 4:08 am

I'm going through some archives at work and updating filename formatting. Our old way was to name files "Filename [Author] (date) (other data etc)". Now, we want to move the [Author] part to the beginning of the file. I know that can be done using regex, but I am a complete newbie and cannot wrap my head around it. Can anybody give me some advice? Thanks!
jackson000
 
Posts: 5
Joined: Sun Oct 18, 2020 4:04 am

Re: Regex help: move a string within filename

Postby jackson000 » Sun Oct 18, 2020 4:32 am

Of course I found the answer right after I posted this.

Match: (.*?) (\[(.*?)\]) (.*?)
Replace: \2 \1 \4
jackson000
 
Posts: 5
Joined: Sun Oct 18, 2020 4:04 am

Re: Regex help: move a string within filename

Postby Admin » Sun Oct 18, 2020 5:37 am

Hi, if you enable Simple regex it can be done with this:

Match: %1 [%2] %3
Replace: %2 %1 %3
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Regex help: move a string within filename

Postby jackson000 » Sun Oct 18, 2020 8:28 pm

That's good to know, thanks!
jackson000
 
Posts: 5
Joined: Sun Oct 18, 2020 4:04 am


Return to Regular Expressions