# Regex and problem with brackets

**URL:** <https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139>\
**Category:** Support\
**Created:** [September 14, 2014, 12:39pm UTC](https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139 "2014-09-14T12:39:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackpots](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jackpots](https://community.mp3tag.de/u/jackpots)\
**Post date:** [September 14, 2014, 12:39pm UTC](https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139/1 "2014-09-14T12:39:44Z")

</div>

I think I need a little assistance with regex in mp3tag.

Have \> aaaa bbbb cccc dddd (xxx xxx xxx) [yyy yyy yyy]  
Want \> bbbb cccc dddd, aaaa (xxx xxx xxx) [yyy yyy yyy]

So I tried the following:

$regexp(%…%,^(.+?)\s(.+?)(\s'[([{]'.+?)\*$,$2',' $1$3)

…but it resulted with:

bbbb cccc dddd, aaaa [yyy yyy yyy]

Any help is appreciated. I am too much in that I am just not seeing the solution. Thanks.

---

<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:** [September 14, 2014, 1:46pm UTC](https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139/2 "2014-09-14T13:46:45Z")

</div>

I have tried it with

$regexp(%comment%,'^(.+?)\s(.+?)(\s[[{(].\*)$','$2, $1$3')

"aaaa bbbb cccc dddd (xxx xxx xxx) [yyy yyy yyy]" -\> "bbbb cccc dddd, aaaa (xxx xxx xxx) [yyy yyy yyy]"

---

<div class="post-metadata">

**Author:** ![jackpots](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jackpots](https://community.mp3tag.de/u/jackpots)\
**Post date:** [September 14, 2014, 2:10pm UTC](https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139/3 "2014-09-14T14:10:50Z")

</div>

Aha! You completely placed the match (& replace) expression in single quotes.

I will use your suggestion. Thank you!

--edit----------------  
For those who came here from a search:

The aim is to set TITLESORT using TITLE as basis, moving articles, such as "the," to the end of the actual title of the track, that is, before ancillary attachments like features, mixes or bonus.

Therefore, we would have the following:  
TITLE: Blah \>\> TITLESORT: Blah  
TITLE: The blah \>\> TITLESORT: blah, The  
TITLE: The blah (Feat. Jenny) \>\> TITLESORT: blah, The (Feat. Jenny)  
TITLE: The blah (Feat. Jenny) [Radio Edit] \>\> TITLESORT: blah, The (Feat. Jenny) [Radio Edit]

Here is the corresponding regex that is applied to TITLESORT:  
$if($eql($regexp(%title%,^(A|An|The|El|Los|La|Las|Le|Les|De)\s,),%title%),,$regexp(%title%,'^(.+?)\s(.+?)(\s[[{(]._)_$','$2, $1$3'))

In general, it uses a condition ($if) to find titles that begin with articles ($regexp 1), and if so, traps the article as a variable and place it, preceded by a comma, at the end of the title but before the extra stuff in brackets ($regexp 2).

My final regex includes a modification: an asterisk (greedily matches 0 or more times) before the end of line anchor, "$."

Alternatively, and a little simpler without the prefixed conditional:  
$regexp(%title%,'^(A|An|The|El|Los|La|Las|Le|Les|De)\s(.+?)(\s[[{(]._)_$','$2, $1$3')

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [September 14, 2014, 3:14pm UTC](https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139/4 "2014-09-14T15:14:15Z")

</div>

> [@jackpots](#):
>
> I think I need a little assistance with regex in mp3tag. ...  
> Any help is appreciated. I am too much in that I am just not seeing the solution. Thanks.

**$regexp(%TITLE%,'^(.+?)\s(.+)\s(\(.+)$','$2, $1 $3')** 

**From: aa bb cc dd (xx xx) [yy yy]  
To: bb cc dd, aa (xx xx) [yy yy]**

 

DD.20140914.1914.CEST

---

<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:** [February 9, 2026, 12:25pm UTC](https://community.mp3tag.de/t/regex-and-problem-with-brackets/16139/5 "2026-02-09T12:25:16Z")

</div>

Closed on February 9, 2026, 12:25pm UTC


