# Regexp to match text between the last brackets in a string

**URL:** <https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858>\
**Category:** Support\
**Created:** [July 9, 2022, 4:19pm UTC](https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858 "2022-07-09T16:19:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nexu](https://community.mp3tag.de/user_avatar/community.mp3tag.de/nexu/32/10040_2.png) [@nexu](https://community.mp3tag.de/u/nexu)\
**Post date:** [July 9, 2022, 4:19pm UTC](https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858/1 "2022-07-09T16:19:14Z")

</div>

I'm bit stuck. I'm looking for the correct regexp (for action) to find text between ( and ) that occur as last.

Right now I have:  
`$regexp(%title%,'^(.+?)\((.+?)\)$','$2')`

But this does not give the correct result if the title string is: "Some song (feat. someone else) (Mixname)".  
The correct result should be in this case: "Mixname".

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [July 9, 2022, 4:51pm UTC](https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858/2 "2022-07-09T16:51:47Z")

</div>

The first match group is marked as non-greedy, trying to match as little as possible. You want the opposite, so

`^(.+)\((.+?)\)$`

should work.

---

<div class="post-metadata">

**Author:** ![nexu](https://community.mp3tag.de/user_avatar/community.mp3tag.de/nexu/32/10040_2.png) [@nexu](https://community.mp3tag.de/u/nexu)\
**Post date:** [July 9, 2022, 5:13pm UTC](https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858/3 "2022-07-09T17:13:25Z")

</div>

Thanks, that was it!

Can't turn my brain on for regexp anymore 🙄 even tho I used to be writing them on daily basis decade ago. It all just looks like hieroglyphs to me, even tho I might have written them myself.

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [July 9, 2022, 5:16pm UTC](https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858/4 "2022-07-09T17:16:36Z")

</div>

I always recommend [https://regex101.com](https://regex101.com) for testing regular expressions — it even gives a short explanation of the different components, so it might help at re-understanding something that was once obvious.

---

<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:** [August 8, 2022, 5:16pm UTC](https://community.mp3tag.de/t/regexp-to-match-text-between-the-last-brackets-in-a-string/57858/5 "2022-08-08T17:16:48Z")

</div>

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