Regular Expressions

RevRagnarok,

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

Use

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

Regards
nickless

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
    to
  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:
^([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.

Upper case for Roman numbers

Regular expression:
\b(?:M{0,3})(?:D?C{0,3}|C[DM])(?:L?X{0,3}|X[LC])(?:V?I{0,3}|I[VX])(?=(\.\s|\s|\)|$))

Replace matches with:
$upper($0)
[ ] 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
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.

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:
$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)

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)

USING:

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

Example:
Blah (blah1) (blah 2)
Result:
Blah

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

Regex:

\s*0(\d+)\s*

Replace with:
$1

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

Regex:

\s*0?(\d+)(\s*/\s*\d+)?\s*

Replace with:

$1

[/quote]

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
Filed: ARTIST
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:
www.regular-expressions.info

kind regards,
Matthias

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
Field: ARTIST
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.

Example:
Elvis Presley /Brel, Jacques/ Gabriele Susanne Kerner [Nena ]
will
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: /

1 Like

These are my Reg-Expressions there may be duplicates to what have previously been posted, or there are small changes to fix the many errors that the posted Reg-Expressions create. I have done a lot of testing to make sure these do what they say they do and nothing else. I hope this also allows me a place to create a back up.
Thank-you! Updated: (June/10/2011) Mp3tag 2.49

Action Group:Aa

RE: Remove track number from title, ex."1 - Title" < "Title".
Field:TITLE
re:^\s*\d+\s*-\s*
Nothing:

RE: Remove "The" from artist, ex."The Artist" < "Artist".
Field:ARTIST
re:^The\s+
Nothing:

Case conversion:
Field:_TAG
Case conversion:Mixed Case
/[({"-_

RE:Capitalize Roman Numerals up to 399. (trimmed down from 3999
RE:to reduce false positives) - <a href="http://bit.ly/lZdZsj" target="_blank">http://bit.ly/lZdZsj</a>
Field:_Tag
re:(?<!')\b(?=[CLXVI])((C{0,3})?((X[LC])|(L?X{0,3})|L)?((I[VX])|(V?(I{0,3}))|V)?)\b
$upper($0)

RE: Capitalize Zero stop Acronyms and Initialisms. - <a href="http://bit.ly/jADbI6" target="_blank">http://bit.ly/jADbI6</a>
Field:_Tag
re:(?:frowning:?<=[^\w\']|\_)|(?<=^))(ac|ad|afi|aol|asap|atm|bbc|bc|bce|blt|btw|cc|cia|crc|cst|csv|dc|dfa|dj|d
mv|doa|dst|eod|ep|est|et|faq|fbi|fm|gi|glc|gmo|imo|imho|iq|ira|jc|irs|krs|la|lp|
m
c|mst|mtd|nasa|oj|pc|pi|pj|pm|ps|qed|rv|sos|ssr|usa|ussr|tba|tbd|teotwawki|tlc|t
v
|ufo)(?=[^\w\']|\_|$)(\.*)
$upper($1)

RE: Capitalize the Letter Infront of a period. A.B.C.
Field:_Tag
re:(?<=\.)([^\W\d\_])
$upper($1)

RE: Capitalize the Letter Infront of a Space and Apostrophe.
Field:_Tag
re:(?<=\s')([^\W\d\_])
$upper($1)

RE: Lower Case Prepositions, Articles and, Coordinating Conjunctions.
Field:_Tag
re:(?<=\w\s)(a|as|at|an|about|above|across|after|against|along|alongside|although|amo
ng|and|around|as|at|because|before|behind|below|beneath|beside|between|beyond|bu
t
|by|de|despite|down|during|even|except|excepting|for|from|if|in|inside|into|like
|
near|next|nor|of|off|on|onto|or|out|outside|over|past|regarding|round|since|so|t
h
an|the|through|throughout|till|to|toward|under|underneath|unlike|until|up|upon|v
o
n|when|while|with|within|without|yet)(?=\s\w)
$lower($0)

RE: Lower Case Abbreviations, Add Stop.
Field:_Tag
re:(?<=[^\w\']|\_)(alt|ave|capt|cent|corp|div|ed|eg|etc|fag|feat|gen|hr|ie|inc|inst|lb|ltd|
min|mt|op|pl|pop|pseud|pt|pub|rev|sec|ser|sgt|st|univ|vs|vol)(?=[^\w\']|\_)(\.*)
$lower($1).

RE: Add Space Before, & ( { [ + =
Field:_Tag
re:([^\W\_])([&\(\{\[\+\=])
$1 $2

RE:Add Space After, & ) } ] ; : , ! + =
Field:_Tag
re:([&\)\}\]\;\:\,\!\+\=])([^\W\_])
$1 $2

RE: Add Space After, .  <a href="http://bit.ly/jADbI6" target="_blank">http://bit.ly/jADbI6</a>
Field:_Tag
re:(?<!^)(?<!\d|\s|\.)(\.)([^\W\d\_])(?!\.|\s|$)
$1 $upper($2)

RE: Add Space After, " "
Field:_Tag
re:(".*?")([^\W\_])(?!$)
$1 $2

RE: Add Space Before, " "
Field:_Tag
re:([^\W\_])(".*?")
$1 $2

RE: Remove Spaces After, ( [ { Before, ] } ) ? : ; , ! .
Field:_Tag
re:([\(\[\{])\s+|\s+([\]\}\)\?\:\;\,\!\.])
$1$2

RE: Remove Spaces Before / After.
Field:_Tag
re:\s+(\/)\s+
$1

RE: Remove Spaces inside, " "
Field:_Tag
re:"\s*(.*?)\s*"
"$1"

RE: Remove Spaces Before and After String.
Field:_Tag
re:^\s+|\s+$
Nothing:

RE: Remove all Double+ Spacing.
Field:_Tag
re:\s{2,}
One Space:

RE: Add Apostrophe to Are Contractions.
Field:_Tag
re:\b(how|they|what|when|where|why|you)re(?=[^\w\']|\_|\$)
$1're

RE: Add Apostrophe to Had/Would Contractions.
Field:_Tag
re:\b(he|how|i|it|she|they|we|what|where|who|why|you)d(?=[^\w\']|\_|\$)
$1'd

RE: Add Apostrophe to Have Contractions.
Field:_Tag
re:\b(could|how|i|might|must|should|we|what|when|where|would|you)ve(?=[^\w\']|\_|\$)
$1've

RE: Add Apostrophe to Is Contractions.
Field:_Tag
re:\b(he|here|how|it|let|she|that|there|two|what|when|where|who|why)s(?=[^\w\']|\_|\$)
$1's

RE: Add Apostrophe to Not Contractions.
Field:_Tag
re:\b(ain|aren|can|couldn|didn|doesn|don|hadn|hasn|haven|isn|mightn|mustn|shoul
dn|wasn|weren|won|wouldn)t(?=[^\w\']|\_|\$)
$1't

RE: Add Apostrophe to Will Contractions.
Field:_Tag
re:\b(how|i|it|she|that|there|they|what|when|where|who|why|you)ll(?=[^\w\']|\_|\$)
$1'll

RE: Add Apostrophe to Am Contractions.
Field:_Tag
re:\b(i)m(?=[^\w\']|\_|\$)
$1'm

RE: Add Apostrophe to Do Ya Contraction.
Field:_Tag
re:\b(D)ya(?=[^\w\']|\_|\$)
$1'ya

RE: Add Apostrophe to Do You Contraction.
Field:_Tag
re:\b(D)you(?=[^\w\']|\_|\$)
$1'you

RE: CamelCase Mc Words.
Field:_Tag
re:\bMc(?=.)
Mc$upper($1)

RE:CamelCase O' Words.
Field:_Tag
re:\bO'([^\W\d\_e])
O'$upper($1)

mp3tagRegExpressions.txt (6.23 KB)

My title and/or filename looks like:

Gospel&spiritual 1 - Track 03.[128kb 44khz 2'34]

I want to delete the suffix: '.[128kb 44khz 2'34]'.

I do it the way:

Field: TITLE
RegExp: (.*)\.\[[0-9]+kb\s[0-9]+khz.*\]
Replace with: $1

Just change that to the field _FILENAME if you want to do it for the filename.

If you want to take a more easy solution (for example delete everything after the first dot, ...) see the next posts from DetlevD or RevRagnarok.

Update: Added a '\' befor the dot, to make sure, only a real dot before the '[' will be replaced, thx to RevRagnarok for the hint.