Swapping text before and after a character

A swapping-ground for Regular Expression syntax

Swapping text before and after a character

Postby enhompe » Mon Sep 14, 2015 4:24 pm

I have some mp3 files which have Artist last name first and first name last, and there's a ~ symbol between the last and first names. I want to rename them so I end up with the Artist first name first, followed by the last name and no ~ symbol.

Here are examples of the filenames I am working with:

Blige~Mary J - Stay Down.mp3
Cribs~The - I'm A Realist.mp3
Rolling Stones~The - Angie.mp3

As you can see, the number of words either before or after the ~ symbol varies, so I have to reference the ~ symbol in the expression.

After processing these files, I hope to end up with the following:
Mary J Blige - Stay Down.mp3
The Cribs - I'm A Realist.mp3
The Rolling Stones - Angie.mp3

So, I need to move the text between the ~ and the hyphen - to the front of the filename, and the text from the beginning of the filename to the ~ needs to end up between after that and before the hyphen -.

I could probably temporarily remove the song titles from the filenames using mp3 Tag and Rename (my mp3 editor of choice). I would then store the titles in a ID3 tag Title Field and put them back into the filename after processing is done. That might make the expression I need simpler. I would be willing to do that if need be.Then the filenames (before processing) would be:

Blige~Mary J.mp3
Cribs~The.mp3
Rolling Stones~The.mp3

And after:

Mary J Blige.mp3
The Cribs.mp3
The Rolling Stones.mp3

This might be an easier expression, because it would just involve swapping the filename text before and after the ~ symbol. Or if someone has done this before, a link to an explanation in the Help would be adequate, I'm sure.

Thank you.
enhompe
 
Posts: 7
Joined: Sat Oct 25, 2014 4:30 pm

Return to Regular Expressions