# Using $regexp() to isolate parts of a large tag, like a cuesheet

**URL:** https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872
**Category:** Mac
**Created:** [March 13, 2026, 7:50pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872 "2026-03-13T19:50:45Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Erichwanh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/erichwanh/32/19236_2.png) [@Erichwanh](https://community.mp3tag.de/u/Erichwanh)
#### Post date: [March 13, 2026, 7:50pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/1 "2026-03-13T19:50:45Z")

</div>

MacOS 26.3.1, MP3tag 1.11.0, Patterns 1.3

Forgive me, all my scripts got lost when my previous comp died last month, and I have to relearn a lot of what I wrote.

**General question** : Is there a site or app where I can test regexes in such a way that they “translate” properly to MP3tag? I use Patterns with it set to “Perl (PCRE)”, but I’m unsure if that matches what’s [stated on the documentation](https://docs.mp3tag.de/regex/).

**Specific Question:** I’m trying to isolate and extract info from Cue sheets, and just cannot remember how I got there for my old script. When I try to grab INDEXes with Patterns, it works fine:

 ![Screenshot 2026-03-13 at 3.30.10 PM](https://community.mp3tag.de/uploads/default/original/3X/c/5/c5b068243946f2abd780fb9620f6254aba4431b0.jpeg)

and if I were to try and “translate” that to MP3tag, I’d want it to read more like:

`^.+?\[\r\n\] TRACK %TRACK% AUDIO.+?((?:\[\r\n\] INDEX \d\d \d\d:\d\d:\d\d)+)(?:.+|$)`

But when I try something like:

`$regexp(%CUESHEET%,'^.+?\[\r\n\] TRACK '%TRACK%' AUDIO.+?((?:\[\r\n\] INDEX \d\d \d\d:\d\d:\d\d)+)(?:.+|$)',$1)`

It doesn’t work, and I don’t know where to start with troubleshooting, because what I’m trying to do works with Patterns. I’m guessing this may be a mistake in my approach.

… thank you kindly in advance for your time, and getting this far. I had a really wonderful action groups .json file with all of these written out, thanks to the great update however long ago, and \*poof\*, one of the few things I lost and it’s one of the more frustrating.

Peace 8^)

---

<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: [March 13, 2026, 7:56pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/2 "2026-03-13T19:56:35Z")

</div>

I think you can test the regular expression in Convert\>Tag-Tag and its Preview

---

<div class="post-metadata">

### Author: ![arb](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@arb](https://community.mp3tag.de/u/arb)
#### Post date: [March 13, 2026, 8:11pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/3 "2026-03-13T20:11:50Z")

</div>

Try out [regex101.com](http://regex101.com), it’s great for breaking down each step of the process and is pretty close to boost.regex/ICU in its default settings. I think as long as you remember to remove/put back those `'` around the pattern and escape any characters that conflict between regex and [format strings](https://docs.mp3tag.de/format/), it’s a good enough workflow.

You can test out your `$regexp()` in a Column for testing but there _might_ be slight differences in how Columns and Convert/Actions process tags so definitely try for real on a live example once you’ve got a formula looking good.

Not sure where to start with a cuesheet, sorry. 😅 Have you got a sample bit of text we could use so we can see how your formula reacts?

---

<div class="post-metadata">

### Author: ![Erichwanh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/erichwanh/32/19236_2.png) [@Erichwanh](https://community.mp3tag.de/u/Erichwanh)
#### Post date: [March 13, 2026, 8:46pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/4 "2026-03-13T20:46:52Z")

</div>

Thank you kindly for the responses 8^)

> [@ohrenkino](#):
>
> I think you can test the regular expression in Convert\>Tag-Tag and its Preview

> [@arb](#):
>
> You can test out your `$regexp()` in a Column for testing but there _might_ be slight differences in how Columns and Convert/Actions process tags so definitely try for real on a live example once you’ve got a formula looking good.

Those are good ideas, thank you. I used to have a test column up, but never thought to use it for regexes.

> [@arb](#):
>
> Not sure where to start with a cuesheet, sorry. 😅 Have you got a sample bit of text we could use so we can see how your formula reacts?

My comp exploded last month so I’m literally starting from scratch, however my old script extracted the INDEXes and then built a brand new cuesheet to my specs. That way I can also use Cuesheets to import my preferred tags, in case I have to rebuild a library due to whatever reason.

So with the example cuesheet I have in the picture:

```plaintext
REM ARTIST "Example"
FILE "Example.flac" WAVE
  TRACK 01 AUDIO
    TITLE "One"
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE "Two"
    INDEX 00 02:54:60
    INDEX 01 02:57:57
  TRACK 03 AUDIO
    TITLE "Three"
    INDEX 00 05:41:67
    INDEX 01 05:45:05

```

What I tried was:

**Format Tag Field**

Field: CUESHEET2  
Format: `$regexp(%CUESHEET%,'^.+?\[\r\n\] TRACK '%TRACK%' AUDIO.+?((?:\[\r\n\] INDEX \d\d \d\d:\d\d:\d\d)+)(?:.+|$)',$1)`

It didn’t work.

I’ll try regex101 again as well, thank you. A few decades ago I learned via JGSoft’s EditPadPro, but not having that program is the punishment for my transgression of switching to Macs, I guess 8^)

---

<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: [March 14, 2026, 9:46am UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/5 "2026-03-14T09:46:42Z")

</div>

My preview does show the original. Which is an indication that the defined pattern does not match the data.  
What may be a source for problems: the cuesheet shows `TRACK 01` and you use `TRACK %track%`.  
Does %track% really have a 2-digit-number?

E.g. this expression  
`$regexp(%cuesheet%,'^.+?\s*TRACK 03 AUDIO.+?((?:\s*INDEX \d\d \d\d:\d\d:\d\d)+)(?:.+|$)',$1)`  
Produces

```auto
    INDEX 00 05:41:67
    INDEX 01 05:45:05"

```

---

<div class="post-metadata">

### Author: ![Erichwanh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/erichwanh/32/19236_2.png) [@Erichwanh](https://community.mp3tag.de/u/Erichwanh)
#### Post date: [March 14, 2026, 11:25am UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/6 "2026-03-14T11:25:52Z")

</div>

> [@ohrenkino](#):
>
> Does %track% really have a 2-digit-number?

For me, yes. I normally use %BASETRACK% (min 2 digits, building %TRACK% from that, %SUBTRACK%, AND %MEDIASIDE%), but I didn’t want my tagging to further confuse anyone looking at this.

---

<div class="post-metadata">

### Author: ![arb](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@arb](https://community.mp3tag.de/u/arb)
#### Post date: [March 14, 2026, 9:21pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/7 "2026-03-14T21:21:48Z")

</div>

I made some amendments between both of your patterns:

```auto
$regexp(%cuesheet%,'^.*?\s*TRACK '$num(%track%,2)' AUDIO\s.*?[\n]((?:\s*INDEX \d\d \d\d:\d\d:\d\d)+).*',$1)

```

The apostrophes in **`‘`** `...` **`’`** `%track%` **`'`** `...` **`'`** splitting up the regex into 3 sections are back to allow `%track%` to be used, `$num()` is just a guarantee that a single-digit `%track%`/``%basetrack%` will have a leading zero.

I had a **lot** of bother getting it to work on regex101 as it turns out that:

`...AUDIO` **`\s`** `.+?`**`[\n]`**`((?...`

was needed as Mp3Tag was passing newlines through `.+?` appropriately but not regex101 or a fair amount of other testing sites. That could be why Patterns was giving you grief too. This should also remove the extra line above your result. Both `.*?` and `.+?` work the same at any rate.

You can always use another regex afterwards to remove the leading spaces, if required.

… on a slightly off-topic note, I have no idea why regex101 outputs the remaining text without the match/group when not substituted with `$1`, yet Mp3Tag actually outputs the matched group alone. 🥲 Hoping someone could enlighten me as to the differences in how outputs are dealt with. Back on topic, another thing to look out for when testing. 😉

---

<div class="post-metadata">

### Author: ![Erichwanh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/erichwanh/32/19236_2.png) [@Erichwanh](https://community.mp3tag.de/u/Erichwanh)
#### Post date: [March 20, 2026, 12:52am UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/9 "2026-03-20T00:52:57Z")

</div>

So, interesting development. I tested this out a few more times in a few more ways:

> [@arb](#):
>
> I made some amendments between both of your patterns:
> 
> ```auto
> $regexp(%cuesheet%,'^.*?\s*TRACK '$num(%track%,2)' AUDIO\s.*?[\n]((?:\s*INDEX \d\d \d\d:\d\d:\d\d)+).*',$1)
> 
> ```

And it just didn’t work. Then I started testing with new-line turned off on Patterns, and this worked on MP3tag:

```auto
$regexp(%CUESHEET%,'^(?:.|\s)+?TRACK '$num(%TRACK%,2)' AUDIO(?:.|\s)+?((?:\s*INDEX \d\d \d\d:\d\d:\d\d)+)(?:.|\s)*$',$1)

```

So then while I was getting there, I realized why I was having so much trouble. I remembered my last script, which took all \n\r and replaced it with #!#. It made traversing the code easier for me at that time. Funny enough, this new one seems better.

I'm going to keep going, but thank you for your help 8^)

---

<div class="post-metadata">

### Author: ![arb](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@arb](https://community.mp3tag.de/u/arb)
#### Post date: [March 20, 2026, 3:58pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/10 "2026-03-20T15:58:56Z")

</div>

I just checked both formulas in iOS Shortcuts and you're right, didn't work 🫩 Must be a difference within ICU regex that I missed, apologies. Yours is working great, only other amendment is:

```auto
$regexp(%CUESHEET%,'^(?:.|\s)+?TRACK '$num(%TRACK%,2)' AUDIO(?:.|\s)+?\n((?:\s*INDEX \d\d \d\d:\d\d:\d\d)+)(?:.|\s)*$',$1)

```

I put the `\n` back which should remove the top newline for you to leave only the lines you need.

---

<div class="post-metadata">

### Author: ![arb](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@arb](https://community.mp3tag.de/u/arb)
#### Post date: [March 20, 2026, 5:07pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/11 "2026-03-20T17:07:25Z")

</div>

Sorry, back again! 😬

I found out ICU is stricter about single/multi-line matching but you can use `(?s)` to fix that:

```auto
$regexp(%CUESHEET%,'(?s)^.*?TRACK '$num(%TRACK%,2)' AUDIO.*?\n((?:\s*INDEX \d{2} \d{2}:\d{2}:\d{2})+).*',$1)

```

That should hopefully allow the previous formula to work in both boost.regex and ICU.

I tested using `^(?:.|\s)+` further to find it was suffering from catastrophic backtracking which shouldn't be an issue as long as `TRACK` matches a value in your `CUESHEET`. When there wasn't a match, it was making my Shortcuts app hang for a while 🫢

---

<div class="post-metadata">

### Author: ![Erichwanh](https://community.mp3tag.de/user_avatar/community.mp3tag.de/erichwanh/32/19236_2.png) [@Erichwanh](https://community.mp3tag.de/u/Erichwanh)
#### Post date: [March 21, 2026, 5:18pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/12 "2026-03-21T17:18:57Z")

</div>

Good timing, I was just coming back here. First off:

> [@arb](#):
>
> I put the `\n` back which should remove the top newline for you to leave only the lines you need.

So, this has directly taught me through context the differences between \s and \n, and that's a big help, thank you. Ironically, I use that top newline in my script, haha. But for this thread's purposes, that works great and I can use the logic for later.

> [@arb](#):
>
> I found out ICU is stricter about single/multi-line matching but you can use `(?s)` to fix that:
> 
> ```auto
> $regexp(%CUESHEET%,'(?s)^.*?TRACK '$num(%TRACK%,2)' AUDIO.*?\n((?:\s*INDEX \d{2} \d{2}:\d{2}:\d{2})+).*',$1)
> 
> ```
> 
> That should hopefully allow the previous formula to work in both boost.regex and ICU.

Excellent, thank you kindly.

Quick question. \d\d and \d{2} are equivalent, right? I only ask because I start using {} at 3, because \d\d is one char shorter.

> [@arb](#):
>
> I tested using `^(?:.|\s)+` further to find it was suffering from catastrophic backtracking which shouldn't be an issue as long as `TRACK` matches a value in your `CUESHEET`. When there wasn't a match, it was making my Shortcuts app hang for a while 🫢

... I noticed that, too, unfortunately. That's been the case with my cuesheet script from the start, that MP3tag not lagging to a halt is contingent on the cuesheets being formatted correctly, \*and\* me keeping to my personal tagging standard. I think that's due to knowing regex well enough to play with it, but not optimize it. So things like `(?s)` never would've crossed my mind (I needed the gui checkbox!).

Thank you once again, kindly.

---

<div class="post-metadata">

### Author: ![arb](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@arb](https://community.mp3tag.de/u/arb)
#### Post date: [March 21, 2026, 5:28pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/13 "2026-03-21T17:28:15Z")

</div>

> [@Erichwanh](#):
>
> \d\d and \d{2} are equivalent, right?

Yep, `\d{3}` would look for three instances of `\d` and `\d{0,2}` would look for between 0-2 instances. But you’re right, `\d\d` is less characters which is an optimisation nonetheless 😛

No problem, it was fun to work on!

(and making me despairingly wary that my other scripts might need a revamp to work with ICU 🫠 )

---

<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: [March 28, 2026, 5:28pm UTC](https://community.mp3tag.de/t/using-regexp-to-isolate-parts-of-a-large-tag-like-a-cuesheet/70872/14 "2026-03-28T17:28:36Z")

</div>

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