# Regex replace up to next bracket and move to artist

**URL:** https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944
**Category:** Support
**Created:** [July 20, 2019, 9:23am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944 "2019-07-20T09:23:15Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Zestje](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/a183cd/32.png) [@Zestje](https://community.mp3tag.de/u/Zestje)
#### Post date: [July 20, 2019, 9:23am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/1 "2019-07-20T09:23:15Z")

</div>

Hello everyone. I'm trying to set up some actions to delete the 'featuring' part from the title by using regex. I'm a total newbie at this and have gotten quite far by searching the forums for help but for now I can't get the following to work:

Current regex is  
Field: TITLE  
Regular Expression: \s+(fe?a?t.\*)  
Replace: (nothing)

When a variant of '(feat' is found this deletes everything up to the end of the tag when additional sets of round brackets are in the tag. I want it to end at the first round bracket after the match. So it should -not- remove any brackets before the match nor any following sets of brackets. For example:  
title (feat. artist2) (radio edit)  
currently becomes:  
title  
instead of:  
title (radio edit)

What do I have to change in the regex to get this to work?  
And additionally: how do I add the exact string that is matched by the regex to the artist field?

Many thanks in advance!  
Wouter

---

<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: [July 20, 2019, 9:31am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/2 "2019-07-20T09:31:00Z")

</div>

see e.g. here:

> [@Complicated Field Editing Format](https://community.mp3tag.de/t/complicated-field-editing-format/45933):
>
> Hello MP3TAG Community, I've recently done very basic tag edits with the help of this community. I'm now looking to create my ideal "End All Be All" tool. I've always put my files into a particular format that I find most suitable for viewing. For clarity's sake, I will show a template and a few examples. One thing to note is that not all songs being edited are remixes, but I choose to show the remix portion in the template because it is integral to many songs in my library, particularly ele…

or here:

> [@Replace multiple tag fields, remove words](https://community.mp3tag.de/t/replace-multiple-tag-fields-remove-words/43670/2):
>
> I guess this one is the swiss-army-knife for removing featuring slight_smile

---

<div class="post-metadata">

### Author: ![Zestje](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/a183cd/32.png) [@Zestje](https://community.mp3tag.de/u/Zestje)
#### Post date: [July 20, 2019, 1:32pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/3 "2019-07-20T13:32:12Z")

</div>

The second topic contained exactly what I needed to get rid of the 'featuring' from the title. Many thanks!

I'm reorganizing my actions now and will then try to make an action to add the found string to the Artist tag before deleting it.

These regex' are extremely powerful, but sometimes hard to 'read'.

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 20, 2019, 5:44pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/4 "2019-07-20T17:44:59Z")

</div>

I was the OP of the first topic that [ohrenkino](https://community.mp3tag.de/u/ohrenkino) linked, and using what I know as well as the second post he linked, I think your best bet might be using the following two part action:

**Field:** ARTIST  
**Format string:** `$meta_sep(artist,\\)\\$regexp(%TITLE%,'^(.+?)\s+[[({]?(?:ft\.?|feat\.?|featuring)\s+([^][(){}]+)[])}]?(\s+.+)?$','$2',1)`

* * *

**Field:** TITLE  
**Format string:** `$regexp(%TITLE%,'^(.+?)\s+[[({]?(?:ft\.?|feat\.?|featuring)\s+(?:[^][(){}]+)[])}]?(\s+.+)?$','$1$2',1)`

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 20, 2019, 5:58pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/5 "2019-07-20T17:58:48Z")

</div>

Sorry about multiple edits on my post, but now the format above should work properly.

---

<div class="post-metadata">

### Author: ![Zestje](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/a183cd/32.png) [@Zestje](https://community.mp3tag.de/u/Zestje)
#### Post date: [July 20, 2019, 6:35pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/6 "2019-07-20T18:35:47Z")

</div>

Hello again,

@krmerman342: The action for the TITLE field matches my current one exactly.  
Your proposal for the ARTIST field doesn't work the way it should however.  
E.g. with

TITLE: songtitle (featuring feat\_artist)  
ARTIST: main\_artist

the first action turn the ARTIST field into:

main\_artist\\feat\_artist

with two backslashes instead of:

main\_artist featuring feat\_artist

(On a side note: I also want to get rid of the brackets)

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 20, 2019, 7:28pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/7 "2019-07-20T19:28:57Z")

</div>

Ah, my apologies. I was attempting to mend a problem you aren't facing.  
You would like a single artist field, not multiple. Instead, try this as the first part:

**Field:** ARTIST  
**Format string:** `%artist% featuring $regexp(%TITLE%,'^(.+?)\s+[[({]?(?:ft\.?|feat\.?|featuring)\s+([^][(){}]+)[])}]?(\s+.+)?$','$2',1)`

---

<div class="post-metadata">

### Author: ![Zestje](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/a183cd/32.png) [@Zestje](https://community.mp3tag.de/u/Zestje)
#### Post date: [July 20, 2019, 7:37pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/8 "2019-07-20T19:37:37Z")

</div>

@kramerman342: Thank you so much, it's working perfectly now!  
I'm still trying to 'decrypt' the regex formulae, it's fascinating what you can do with them.

Again thank you both very much for helping out!

Wouter

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 20, 2019, 7:47pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/9 "2019-07-20T19:47:38Z")

</div>

Something I'd like to suggest that you may have already tried:  
[https://regexr.com/](https://regexr.com/)  
The website I linked may be inconsistent in some ways with what you input into MP3TAG, but it helped me a lot in making SOME sense out of what is happening "behind the scenes" of the regex. By hovering over your code you can read snippets of how the characters might interact with your tag in question. It will not show the exacts always, so beware and be sure to always test on one file before you use your regex on a collection of files!

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 21, 2019, 5:11pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/10 "2019-07-21T17:11:42Z")

</div>

@Zestje  
This new website I'm linking is nearly identical in appearance to the last one I linked, but seems to do a better job at tracking the function of parenthesis/brackets as well as giving you that same visual representation of what's happening in your specific text (your tag), which I've already input so you can see it straight away!

> **[Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript](https://regex101.com/r/UeDAec/1)**
>
> Regex101 allows you to create, debug, test and have your expressions explained for PHP, PCRE, Python, Golang and JavaScript. The website also features a community where you can share useful expressions.

---

<div class="post-metadata">

### Author: ![Zestje](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/a183cd/32.png) [@Zestje](https://community.mp3tag.de/u/Zestje)
#### Post date: [July 21, 2019, 6:06pm UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/11 "2019-07-21T18:06:57Z")

</div>

@kramerman342: Thank you very much, that website is amazing! Is really helped me understand the final bits of code.

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 22, 2019, 3:45am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/12 "2019-07-22T03:45:00Z")

</div>

Hey, I know that this post is solved, but this may just be a good spot for me to ask a question based on the regex that has already been used in this thread.  
We know that using this:  
**Field:** ARTIST  
**Format string:** `%artist% featuring $regexp(%TITLE%,'^(.+?)\s+[[({]?(?:ft\.?|feat\.?|featuring)\s+([^][(){}]+)[])}]?(\s+.+)?$','$2',1)`  
is useful in taking away the (feat.\_artist) part of the tag, but what if instead we wanted to copy over a Remix artist? I'm having a tough time rearranging to achieve that goal. I specifically want this style where all brackets (, [ & { are accounted for. Thanks to anybody who might be able to help.  
@ohrenkino sorry to bother, but you always help me figure out what I might be missing! might you have any ideas?

P.S. I was able to create this:  
`$regexp(%title%,(.*)\s(?:[({[])(.*?[mM]ix|.*?[eE]dit|.*?[vV]ersion|.*?[aA]coustic)(?:[)}\]]),$1[$2]`  
`https://regex101.com/r/0Z7XR9/7`  
Which appears to do EXACTLY what I need it to. Bringing it into MP3TAG doesn't quite work, though. There must be some slight tweak that I have to do to make it work!

---

<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: [July 22, 2019, 5:27am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/13 "2019-07-22T05:27:43Z")

</div>

> [@kramerman342](#):
>
> .S. I was able to create this:  
> `$regexp(%title%,(.*)\s(?:[({[])(.*?[mM]ix|.*?[eE]dit|.*?[vV]ersion|.*?[aA]coustic)(?:[)}\]]),$1[$2]`

I doubt that this expression would have worked at the other address as it is missing a closing parenthesis at the end.  
You can test the regular expressions in MP3tag in the function Convert\>Tag-Tag.

> [@kramerman342](#):
>
> if instead we wanted to copy over a Remix artist? I

What are the characteristics of a Remix artist?  
Regular expressions are all about patterns, they do not see any sematics. So you have to find the pattern and then use the regular expression to describe that pattern.  
If the remix artist stands between the opening parenthesis and in front of the keyword Remix, then you have to cater for that by moving the part

> [@kramerman342](#):
>
> (\s+.+)

to front and adapt the keywords.

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 22, 2019, 6:36am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/14 "2019-07-22T06:36:08Z")

</div>

> [@ohrenkino](#):
>
> You can test the regular expressions in MP3tag in the function Convert\>Tag-Tag.

I can't believe I didn't know this.

> [@ohrenkino](#):
>
> I doubt that this expression would have worked at the other address as it is missing a closing parenthesis at the end.

I also need to get better at rechecking before I post things. You're right about the closing parenthesis. When I used the function, there was an opening and closing parenthesis. I failed to copy the ending one. The website I linked just showed it as working (i know the program may differ) so I thought maybe I was close.  
In the context of what I need this to work for, a remix artist is any artist in a grouping followed by the word "Remix."  
As an example, in the following:  
**Title:** SongName (Feat. Artist2) (RemixArtist Remix)

Let me be straightforward. I'm attempting to create a formatting tool that will discover any grouping ending in Mix/mix, Dub, Edit, Version, or Acoustic (or non-capitalized versions of each word), whether the grouping uses brackets, parenthesis, braces, or a mix-matched combination like ( } or [ ) that anything. I can then use another method to call out specifically my "Remix Artist."  
I need a formatting tool that does this:  
SongName (Feat. Artist2) (RemixArtist Remix) \>\>\> SongName (Feat. Artist2) [RemixArtist Remix]  
SongName (Feat. Artist2) [RemixArtist Edit} \>\>\> SongName (Feat. Artist2) [RemixArtist Edit]  
SongName (Feat. Artist2) {RemixArtist acoustic) \>\>\> SongName (Feat. Artist2) [RemixArtist acoustic]  
SongName (Feat. Artist2) {Extended version} \>\>\> SongName (Feat. Artist2) [Extended version]  
SongName (Feat. Artist2) [DubArtist Dub] \>\>\> SongName (Feat. Artist2) [DubArtist Dub]

---

<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: [July 22, 2019, 7:29am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/15 "2019-07-22T07:29:58Z")

</div>

Perhaps this:  
`$regexp(%TITLE%,'^(.*?)\s+[\({](.*?)[\)}]\s+[\({](.*)[\)}]',$1 ($2) '['$3']')`

If you want to use more unique separators, I would even suggest to use `< >` to separate the featured artist - as there are sometimes titles that have normal parenthesis just as an amendment like  
Pink Floyd: Pigs (three different ones).  
So the regexp could become:  
`$regexp(%TITLE%,'^(.*?)\s+[\({](.*?)[\)}]\s+[\({](.*)[\)}]',$1 <$2> '['$3']')`

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 22, 2019, 8:29am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/16 "2019-07-22T08:29:00Z")

</div>

> [@ohrenkino](#):
>
> $regexp(%TITLE%,'^(.\*?)\s+({[)}]\s+({[)}]',$1 \<$2\> '['$3']')

I can't seem to get this to work, but I'm going to look over it and see if I can't work something out.

I have found a solution that work for the current set-up, but I think I've made it far too convoluted and it also get confused if there's no **feat. artist**. If you'd like to take a look, this is the mess I've created:  
`$regexp(%TITLE%,'^(.*?)\s[[({]+(?:.+)?[[({]+(Mix|.+?Acoustic|.+?Edit|.+?Version|.+?Dub|.+?Remix)[])}]?$',$1' ['$2']')`  
see my results:

* * *

"Song1 Has Long Name (Feat. Artist2] (MixArtist Remix)" -\>  
"Song1 Has Long Name [MixArtist Remix]"

"Summer Days (feat. Macklemore & Patrick Stump of Fall Out Boy) (Junior Sanchez Remix)" -\>  
"Summer Days [Junior Sanchez Remix]"

"Track 3 Doesnt have Feature (Great Remix)" -\>  
"Track 3 Doesnt have Feature (Great Remix)"

\*Note that the third did not change as hoped.  
EDIT: It also completely deletes the featured artist, which I overlooked completely.

---

<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: [July 22, 2019, 8:39am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/17 "2019-07-22T08:39:27Z")

</div>

If the quote is that what you tried then it will not work as you are missing the bits inside the parenthesis.  
I tested mine  
`$regexp(%TITLE%,'^(.*?)\s+[({](.*?)[])}]\s+[\({](.*)[\)}]',$1 <$2> '['$3']')`  
on  
"Song1 Has Long Name (Feat. Artist2] (MixArtist Remix)"  
and the result is:  
"Song1 Has Long Name \<Feat. Artist2\> [MixArtist Remix]"  
(I left out the square brackets as it looked to me that if they were there, everything was ok already but you can add any kind of these to the leading and trailing bits.  
After you have classified the various pieces of data (title, featured artist, version) it should be easy to separate them to other fields.

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 22, 2019, 8:46am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/18 "2019-07-22T08:46:21Z")

</div>

Nice! Upon trying it out on the same examples, it seemed to work on the first two, but suffered the curse of the third one in that it did not change it.

 ![Untitled](https://community.mp3tag.de/uploads/default/original/2X/a/aaca74c681abeec7112aa8d5d6ae4d1345b6aeac.jpeg)

---

<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: [July 22, 2019, 8:50am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/19 "2019-07-22T08:50:12Z")

</div>

> [@kramerman342](#):
>
> the third one in that it did not change it

> [@ohrenkino](#):
>
> Regular expressions are all about patterns, they do not see any sematics.

the third case is a different pattern: just a single pair of brackets.  
So you need a different regexp.

---

<div class="post-metadata">

### Author: ![kramerman342](https://community.mp3tag.de/user_avatar/community.mp3tag.de/kramerman342/32/6650_2.png) [@kramerman342](https://community.mp3tag.de/u/kramerman342)
#### Post date: [July 22, 2019, 8:54am UTC](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944/20 "2019-07-22T08:54:36Z")

</div>

I see. I thought that perhaps I could make one that would serve both purposes. My mistake! Thank you, though. You've been helpful as always! 🙂

[Next page](https://community.mp3tag.de/t/regex-replace-up-to-next-bracket-and-move-to-artist/45944.md?page=2)
