# RegEx example to extract values matching 00\_00\_00 from a set of inconsistently named files

**URL:** https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602
**Category:** Support
**Created:** [October 30, 2023, 12:14am UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602 "2023-10-30T00:14:01Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [October 30, 2023, 12:14am UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/1 "2023-10-30T00:14:01Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [October 30, 2023, 6:35am UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/2 "2023-10-30T06:35:04Z")

</div>

> [@mlmp3](#):
>
> YY-MM-DD dates in the file names

> [@mlmp3](#):
>
> 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

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.  
`$regexp('stringstuff39_09_21morestuff.mp3',.*(\d\d_\d\d_\d\d).*,$1)`  
should work.

> [@mlmp3](#):
>
> 39-09-21stuff.mp3

Has a hyphen instead of an underscore, so the pattern does not match.  
You could use  
`$regexp('stringstuff39-09-21morestuff.mp3',.*(\d\d.\d\d.\d\d).*,$1)`  
Or  
`$regexp(%_filename%,.*(\d\d.\d\d.\d\d).*,$1)`  
for all of these files.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [October 31, 2023, 1:55pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/3 "2023-10-31T13:55:29Z")

</div>

3 posts were split to a new topic: [Delete digits from filename](https://community.mp3tag.de/t/delete-digits-from-filename/62620)

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 1, 2023, 2:23pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/4 "2023-11-01T14:23:08Z")

</div>

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

Funny\_Side\_Up\_xx-xx-xx\_Check\_For\_Water\_Bill.mp3  
to  
{album} - Funny\_Side\_Up  
{comment} xx-xx-xx  
{title} - Check\_For\_Water\_Bill

Flying\_Hutchinsons\_The\_39-08-14\_Scroll\_Of\_All\_Nations  
{album} - Flying\_Hutchinsons\_The  
{comment} 39-08-14  
{title} - Scroll\_Of\_All\_Nations

Face\_to\_the\_Future\_60-xx-xx  
{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.

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

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [November 1, 2023, 2:26pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/5 "2023-11-01T14:26:50Z")

</div>

> [@mlmp3](#):
>
> field COMMENT  
> expression `(%_filename%,.*(\d\d.\d\d.\d\d).*,$1)`

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

> [@ohrenkino](#):
>
> Format string: `$regexp(%_filename%,.*(\d\d.\d\d.\d\d).*,$1)`

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 1, 2023, 2:30pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/6 "2023-11-01T14:30:24Z")

</div>

Here's one:

filename - Stars\_for\_the\_Defense\_52-xx-xx\_First\_Song\_-\_I\_Wanna\_Be\_Happy.mp3

![image](https://community.mp3tag.de/uploads/default/original/2X/6/6347e5a1aca50ef0a88fd5af2b4561898c20b3ad.png)

this one works fine of course:

filename - Stars\_Over\_Paradise\_41-11-28\_Sandra\_Leaves\_Gordon.mp3

![image](https://community.mp3tag.de/uploads/default/original/2X/0/04a4219ddb9f0e524a1e455e5588af5038ad2fa8.png)

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.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [November 1, 2023, 2:33pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/7 "2023-11-01T14:33:44Z")

</div>

AFAIC tell

> [@mlmp3](#):
>
> Stars\_for\_the\_Defense\_52-xx-xx\_First\_Song\_-\_I\_Wanna\_Be\_Happy.mp3

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.

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 1, 2023, 2:34pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/8 "2023-11-01T14:34:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [November 1, 2023, 2:41pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/9 "2023-11-01T14:41:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 3, 2023, 12:54pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/10 "2023-11-03T12:54:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 3, 2023, 1:11pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/12 "2023-11-03T13:11:49Z")

</div>

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

![image](https://community.mp3tag.de/uploads/default/original/2X/b/bcf38a41d9a28cf93bd0589ae19c2390adfb2dd7.png)

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.

![image](https://community.mp3tag.de/uploads/default/original/2X/0/0ede666abf46b6ceae15c81fe51256f08d520fcb.png)

I read the documents but the $regex function at ([Replace with Regular Expression – Mp3tag Documentation](https://docs.mp3tag.de/actions/replace-regexp/)) 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.

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 3, 2023, 1:21pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/13 "2023-11-03T13:21:26Z")

</div>

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

```auto
/.+?(?=abc)/

```

(from [regex - How can I match "anything up until this sequence of characters" in a regular expression? - Stack Overflow](https://stackoverflow.com/questions/7124778/how-can-i-match-anything-up-until-this-sequence-of-characters-in-a-regular-exp))

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

![image](https://community.mp3tag.de/uploads/default/original/2X/9/932ea9fffbf96d220f32d900f1f0687d607834b4.png)

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [November 3, 2023, 1:53pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/14 "2023-11-03T13:53:07Z")

</div>

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

A working regex for exactly this filename:  
`Famous_Fathers_41-xx-xx_24_Fathers_In_The_Household`  
to get the ALBUM from the \_FILENAME would be:  
`$regexp(%_FILENAME%,(.*)_(\d\d-xx-xx)_(.*),$1,1)`  
To get the COMMENT replace `$1` with `$2`  
To get the TITLE replace `$1` with `$3`

![RegExp Parts of Filename](https://community.mp3tag.de/uploads/default/original/2X/8/871a3455d0778fd9f4607df362c53c76af28a67e.gif)

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [November 3, 2023, 2:27pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/15 "2023-11-03T14:27:00Z")

</div>

> [@mlmp3](#):
>
> 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,

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%

---

<div class="post-metadata">

### Author: ![mlmp3](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mlmp3](https://community.mp3tag.de/u/mlmp3)
#### Post date: [November 3, 2023, 9:27pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/16 "2023-11-03T21:27:11Z")

</div>

That worked! Thanks so much!

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [December 3, 2023, 9:27pm UTC](https://community.mp3tag.de/t/regex-example-to-extract-values-matching-00-00-00-from-a-set-of-inconsistently-named-files/62602/17 "2023-12-03T21:27:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
