This thread collects some useful regular expressions.
If you created a regular expression which solves a common task, please post it here and give a short description what it is supposed to do.
These regular expressions can be used with the action type Replace with regular expression. Please look at FAQ: How do I create a new action? to learn more about actions in Mp3tag.
If you have problems with a regular expression, please open a separate topic.
This one will remove the track-number (if followed by a dash) and white space at the beginning of a string
(for instance 01 - Come Together will become Come Together)
Regular expression: ^\s*[0-9]+\s+
Replace with:
This one will remove the track-number if followed by a white space
(for instance 01 Come Together will become Come Together)
Here is another one.
I don't think it will be useful as such to a lot of people, but with REGEXP, examples are never too many
My files were tagged as such: name of the artist.2003AL-name of the album
(the 2003AL meaning: released in 2003, Album, Live, but it could be 1977A, or 1995IR)
Weird, I know
I wanted to change that to a simpler 2003-name of the album
Here is what I did:
Regular expression: .*\.([0-9]*).*-(.+)
Replace with: $1-$2
Another one, that switches first and last names (for instance, Jacques Brel will become Brel, Jacques): Regular Expression:^(.+)\s(.+)$ Replace with:$2, $1
I've noticed a lot of these RegExs 'go overboard' in their matching. A key to good expressions are limiting (1) the false matches and (2) the how long the engine needs to analyze the string.
For example, my two favorite expressions I have posted here are both above on this page. However, they have very greedy matchers that can easily result in lost data.
phoenixdarkdirk's - why NOT limit the track 'numbers' to digits with \d+ ?
mll's - really went overboard when a simple ^(\d)$ would've done it.
I highly recommend this book if you are serious about using REs. Of course, I recommend trying to find it at a technical library, because if you look it over a little you may realize you were just kidding and save yourself the money.
Of course, when we are using them on a handful of MP3 files, it's no big deal. It's when you are handling megabytes of text files that it really matters.
Edit 5 Apr 2013 - After over eight years, fixed the URL to my blog.
This RegEx will convert abbreviations composed of single chars and points between (and/or behind it) to uppercase.
Single chars without points around remains lowercase, except if a "-"char and a space is before it. (Example: "Songname - A text")
First step:
Format Value
Field: TITLE
Formatstring: %_FILENAME%
Second step:
Set a new Replace with Regular Expression action
Field: TITLE
Regular expression:
^([0-9]+)\s*-\s*
Replace matches with:
$1. $2
I use the first format for all file names, but my iRiver displays the title tag, which looks better (and saves one character) using the latter. For me it's a 2-step process: Filename-to-Tag (%TITLE% only) and then convert Title tag. Assumes your filename is the way you want it, of course.
It's taken me far too long to figure it out but I've finally got it working.
To change Horne, Lena to Lena Horne or
Hawkins, Coleman With Manny Albam & His Orchestra to Coleman Hawkins With Manny Albam & His Orchestra
Field: ARTIST
Regular Expression: ^([\w]+),\s([\w]+)
Replace Matches with: $2 $1
I hope I didn't miss the answer in here somewhere. If there's an easier or better way please feel free to help.
This regex can remove/replace all but the last dot from a string. It's useful for people like me who prefer to limit filename chars to a-z, 0-9, '_', and '-'. We need to save that last dot for file extensions.
I recently converted all my wma files to mp3 only to realize that all the tags were lost. My music is in the form:
...\artist\album\track title.mp3
MP3TAG came to my rescue! Not sure whether there was an easier way to do this, but I got started by reading this. Sorry if these are lame ways of doing it, but it's my 1st experience with regexp.
format artist: $regexp(%_folderpath%,.+\\(.+)\\(.+)\\,$1)
format album: $regexp(%_folderpath%,.+\\(.+)\\(.+)\\,$2)
Next 2 I got from ThurstonX in this post.
format track: $regexp(%_filename%,(\d*)\s?(.+),$1)
format title: $regexp(%_filename%,(\d*)\s?(.+),$2)