Regular Expressions

If you have a filename:

  • 01 Trackname
and want it to be
  • 01 - Trackname
create an Action with the following properties:
  • Field: _FILENAME
  • Regular Expression: ([0-9]+)\s
  • Replace matches with: $1 - $2

Edit: Topic merged by moderator.
1 Like

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. :wink: 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.


Thanks a lot for your suggestions. I've changed the expressions you've mentioned to be less greedy.

Best regards,
~ Florian

1 Like

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")

RegEx: ( |\.|^)(\w)(?= |\.|$)
Replace with: $1$upper($2)and
RegEx: ([^-])( \u )
Replace with: $1$lower($2)

Example: a.b a Reg.eX in p.o.d p. diidi e.t. - a bad a.i

A.B a Reg.eX in P.O.D P. diidi E.T. - A bad A.I

Both regular expressions should be executed one after another


RegEx: ( \u )
Replace with: $lower($1)instead of second RegEx to have chars after " - " lowercase too. (Example: "Songname - a text")


Edit: removed some unnecessary characters from RegEx

Title Tag Conversion

This 2-step action does:

  1. set Title tag to Filename
  2. convert titles using, e.g.:
    01 - Track Name
  3. Track Name

First step:
Format Value
Field: TITLE
Formatstring: %_FILENAME%

Second step:
Set a new Replace with Regular Expression action
Field: TITLE
Regular expression:
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.

Upper case for Roman numbers

Regular expression:

Replace matches with:
[ ] case-sensitive comparison

Convert artist names in the form 'Artist, The'

Regular expression: (.*),\sthe$
Replace with: The $1

1 Like

And the other way around

Move "The " to the end

Regular expression: ^The (.+)
Replace with: $1, The

So "The Cure" becomes "Cure, The"
And "The a whole lot of words" becomes "a whole lot of words, The"

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
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.

1 Like

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.

Regex: .

Assumes file extensions are 2-4 chars long (not including the dot). If you are curious how this works google regex lookaround.

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:

format album:

Next 2 I got from ThurstonX in this post.

format track:

format title:

This program saved me TONS of time...

Another member helped me creating one of the most useful REGEXP that i use so far:

From this:

Röyksopp - Beautiful DAY withOUT yoU (Rex The Dog Remix)

To this:

Röyksopp - Beautiful day without you (Rex The Dog Remix)


Action type: Replace with regular expression
Field: TITLE
Regular expression: ^(.*?)((|$)
Replace matches with: $caps3($1)$2
[ ] case-sensitive comparison

See the original thread here

Really simple but this will remove any parenthesis and its contents in any part of the string

Blah (blah1) (blah 2)

Regular expression: (.+?)

Replace matches with:

I dislike it when a leading zero appears in the track number of the track tag (or when the total track count is added after a '/' char).

[Aside: It seems like a bad idea to pollute a nice simple tag like the track with extra information like this. My intuition is that the information in each tag should be kept as simple and pure as possible. In databases there is a similar concept: you usually want to achieve what is called a normalized design. But if someone has a good reason for doing otherwise, please educate me!

Note that I only have a problem with leading zeroes in the track TAGS. In contrast, when I use tracks in filenames, I DO like a leading zero if there are > 9 tracks on the CD because that causes the filenames to be lexicographically ordered, which is critical for proper sorting by your file system, as well as it visually looks better when filenames are displayed in a list.]

Earlier in this thread, phoenixdarkdirk pointed out how to remove any '/' char and following digits.

Here is how to remove any leading zeroes (as well as trimmable whitespace):



Replace with:

Actually, here is a single regex that does everything that I want:



Replace with:



This will remove any trimable whitespace around the number (which will be the track tag in my case), remove any leading zero from the number, and remove any suffix after the number that starts with a '/' char (e.g. the total track count).

I've just spent a while figuring this out myself, and came on here to post it only to find someone else already has :slight_smile:
Mine is quite similar
RegExp: ^(.+),\s+(\w*)
Replace With: $2 $1

Seems to work the same

Thank you so much for this! You saved me a LOT of time! :smiley:

I've split some off-topic posts to Problem with Actions and Regular exp​ressions.

This is not a regular expression for mp3tag, but a link to a page which contains lots of information about creating and using regular expressions.

In my oppinion everybody who uses regexp should have read it :wink:

kind regards,

Switches first and last names

Thank you!
I developed it a little.

Variant A
It will not change those artists, where the conversion already done (artist has comma).
Example: Brel, Jacques William remains Brel, Jacques William

Action: regular expression
Regular expression: ^([^,]+)\s([^,]+)$
Replace with: $2, $1

Variant B
It handles multipled for WMP artists (in format "artist1/artist2/artist3"), possible nicknames at the end in square brackets and trims unnecessary white spaces.

Elvis Presley /Brel, Jacques/ Gabriele Susanne Kerner [Nena ]
Presley, Elvis/Brel, Jacques/Kerner, Gabriele Susanne [Nena]

Action group

  1. action: regular expression (trim white spaces)
    Field: ARTIST
    Regular expression: ^\s+|\s+$
    Replace with: (nothing)

  2. action: regular expression (multiple white spaces replace to 1)
    Field: ARTIST
    Regular expression: \s{2,}
    Replace with: " " (whitout quotation marks)

  3. action: replace (delete white space after opening bracket)
    Field: ARTIST
    Original: "[ " (whitout quotation marks)
    Replace with: [

  4. action: replace (delete white space before closing bracket)
    Field: ARTIST
    Original: " ]" (whitout quotation marks)
    Replace with: ]

  5. action: split fields by separator (for the next actions)
    Field: ARTIST
    Separator: /

  6. action: regular expression (switches names without nickname)
    Field: ARTIST
    Regular expression: ^([^,[]+)\s([^,[]+)$
    Replace with: $2, $1

  7. action: regular expression (switches names with nickname)
    Field: ARTIST
    Regular expression: ^([^,[]+)\s([^,[]+)\s(\[.+\])$
    Replace with: $2, $1 $3

  8. action: merge duplicate fields (...back)
    Field: ARTIST
    Separator: /