RegEx example to extract values matching 00_00_00 from a set of inconsistently named files

I have a set of files with YY-MM-DD dates in the file names, but they're really inconsistent:

  • A_39_09_21_morestuff.mp3
  • 39_09_21ABC.mp3

I'd like to parse these values out and write them to the comment field. Been trying to puzzle out $regex(%title%,d{2}_d{2}_d{2}) but that doesn't seem to work for files like

  • stringstuff39_09_21morestuff.mp3

  • string_stuff_39_09_21+_more+stuff.mp3

  • 39-09-21stuff.mp3

  • stuff39-09-21.mp3

I can eventually work out the right regex but I can't get the $regex function to work and am looking for an example.

Are there any examples of parsing a result from a regex and writing that parsed value into a field?

The filename isn't the title.
The regular expression you use does not use the correct syntax. It should be \d for digits.
Alos, I am missing the result part.
should work.

Has a hyphen instead of an underscore, so the pattern does not match.
You could use
for all of these files.

1 Like

3 posts were split to a new topic: Delete digits from filename

Thanks. I think that will help. The files are set up where everyhting is underscored so I want to parse files like

{album} - Funny_Side_Up
{comment} xx-xx-xx
{title} - Check_For_Water_Bill

{album} - Flying_Hutchinsons_The
{comment} 39-08-14
{title} - Scroll_Of_All_Nations

{album} - Face_to_the_Future
{comment} 60-xx-xx
{title} -

I'm OK doing multiple tag-tag passes, but I can't get the "take 00-00-00" part to work. I get that xx-xx-xx won't match the regex and that's ok but the other two should be parsing and they're not.

I copied file name ot title and am trying to use tag-tag but spec below doesn't return anything.

expression (%title%,.*(\d\d.\d\d.\d\d).*,$1)

Could you show what you enter exactly? Because "Expression" is no valid function.
It should be:

Here's one:

filename - Stars_for_the_Defense_52-xx-xx_First_Song_-_I_Wanna_Be_Happy.mp3


this one works fine of course:

filename - Stars_Over_Paradise_41-11-28_Sandra_Leaves_Gordon.mp3


My ultimate goal is to parse the filename before 00-00-00 into album, the 00-00-00 (or 00-xx-xx) into comment and everything after into title. Because the whole name is delimited with _, I can't just use filename->tag.

AFAIC tell

does not have 3 pairs of digits separated by any character but only 2 digits ("52") followed by another string which happens to have something like placeholders in the shape of "-xx-xx".
But those x-ses are no digits.

Right, that's kind of my next problem. At this point I'm wondering if it would be better just to go with a Python program to read the directories and fileglob, but i think MP3Tag is a really capable program and it -almost- seems possible.

Thanks for your help, I appreciate it.

I am always a friend of filters - so why don't you filter for
%_filename% HAS -xx-xx
and then treat the files with
Format string: $regexp(%_filename%,.*(\d\d-xx-xx).*,$1)
And then you check for files that do not have a comment and the digits
%_filename% MATCHES "\d\d.\d\d.\d\d" AND %comment% MISSING
and treat it with the other regular expression?

I doubt that a python script would do any better if the found pattern is not really clear.

I'll try that - thanks for all the help! Marking your answer as solution.

Deleted the previous post as it didn't have a leading 0 but this one does:


I want to parse the filename as

  1. Part before 00-xx-xx : Album (Famous_Fathers)
  2. Part including 00-xx-xx: Comment (41-xx-xx)
  3. Part after 00-xx-xx: Title (24_Fathers_In_The_Household)

Can I do this in one pass, and if not how can I specify those parts? Tag-Tag at least parsed something but Filename-Tag doesn't parse anything, I think because it wants you to tell it %album%%title%%comment% but the duplicate _ delimiter here makes that impossible.


I read the documents but the $regex function at (Replace with Regular Expression – Mp3tag Documentation) didn't offer any examples, if there are examples somewhere of parsing a regex into multiple fields (or doing multiple regexes, etc) I will work on adapting those but right now I can't seem to get started with anything that works.

I got this regex from stackexchange to find all before a string:


(from regex - How can I match "anything up until this sequence of characters" in a regular expression? - Stack Overflow)

but my attempt to implement it to parse Famous_Fathers into ALBUM still returns the whole file name:


You can not match _xx_xx if your filename includes -xx-xx

A working regex for exactly this filename:
to get the ALBUM from the _FILENAME would be:
To get the COMMENT replace $1 with $2
To get the TITLE replace $1 with $3

RegExp Parts of Filename

Try an action of the type "Guess value" with
Source: $replace($regexp(%_filename%,(.*)(\d\d-xx-xx)(.*),$1==$2==$3),_, )
Target string: %album%==%comment%==%title%

1 Like

That worked! Thanks so much!