# RegExp required to remove bracketed text when there is two sets of brackets

**URL:** https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050
**Category:** Support
**Created:** [November 12, 2022, 2:34pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050 "2022-11-12T14:34:38Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![TersonWatt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/tersonwatt/32/12613_2.png) [@TersonWatt](https://community.mp3tag.de/u/TersonWatt)
#### Post date: [November 12, 2022, 2:34pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/1 "2022-11-12T14:34:38Z")

</div>

Hi

I've been using a RegExp expression in an action to remove bracketed text for many years.

Regular expression: `\(.*\)`

Replace with:

However, it removes all the bracketed text. I'd like a RegEx expression that will remove one set of bracketed text.  
e.g.  
ORIGINAL: Escape (The Pina Colada Song) (Original 1979 7inch Single Version)  
AFTER ACTION: Escape (The Pina Colada Song)

I've been trying some code but I'm not experienced enough to get the right syntax.

The code I've tried:  
Regular expression: `(.*) \s\(.*\)\s \(.*\)`  
Replace with: `$1 $2`

Any helping in solving this will be much appreciated. Thanks in advance for any help that can be provided.

Cheers Terson

---

<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 12, 2022, 2:35pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/2 "2022-11-12T14:35:44Z")

</div>

You want to remove always the last pair of brackets an its content?  
Even if there are more then 2 pairs?

---

<div class="post-metadata">

### Author: ![TersonWatt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/tersonwatt/32/12613_2.png) [@TersonWatt](https://community.mp3tag.de/u/TersonWatt)
#### Post date: [November 12, 2022, 2:38pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/3 "2022-11-12T14:38:28Z")

</div>

Thanks for your instant reply.

Yes, to remove the last set of bracketed text.

---

<div class="post-metadata">

### Author: ![MotleyG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/motleyg/32/440_2.png) [@MotleyG](https://community.mp3tag.de/u/MotleyG)
#### Post date: [November 12, 2022, 2:52pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/4 "2022-11-12T14:52:25Z")

</div>

I think this was just covered not long ago here.

> [@Remove Parentheses from Title](https://community.mp3tag.de/t/remove-parentheses-from-title/49158/9):
>
> This regular expression search for the first opening bracket ( then any character until a closing bracket ) which has to be at the end $ to be matched. If you replace it with nothing, this results in removing the matching characters between and including the brackets. This works for (blabla) in the example title text My text in a title (blabla) and becomes My text in a title This works NOT for the example title text, where the closing bracket is not at the end of the title. My …

---

<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 12, 2022, 3:02pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/5 "2022-11-12T15:02:11Z")

</div>

> [@TersonWatt](#):
>
> Yes, to remove the last set of bracketed text.

To remove only the last set of bracketed text - and let other bracketed text untouched - you could try this regular expression:  
Regular Expression: `\s+\([^)]+\)([^()]*)$`  
Replace with: `$1`

Format string for the Convert Tag-\>Tag for the example tag %TITLE%:  
`$regexp(%TITLE%,'\s+\([^)]+\)([^()]*)$',$1)`

Short Explanation:

 ![image](https://community.mp3tag.de/uploads/default/original/2X/1/12b6fb2a6f4dd1c7771d232e0ece076d6112b643.png)

Search for a white space before an opening bracket and "ignore every closing bracket" until the last closing bracket before the last bracketed text is reached. Group this last one together.  
Replace this group with nothing = remove it.

This works for  
`Escape (The Pina Colada Song) (Original 1979 7inch Single Version)`  
-\> Escape (The Pina Colada Song)  
but also for  
`Escape (The Pina Colada Song) (Original 1979 7inch Single Version) another Text`  
-\> Escape (The Pina Colada Song) another Text

As always with regular expressions:  
Please test it carefully with test data before you use it on all your precious songs!

---

<div class="post-metadata">

### Author: ![TersonWatt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/tersonwatt/32/12613_2.png) [@TersonWatt](https://community.mp3tag.de/u/TersonWatt)
#### Post date: [November 12, 2022, 3:10pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/6 "2022-11-12T15:10:50Z")

</div>

> [@LyricsLover](#):
>
> Regular Expression: `\s+\([^)]+\)([^()]*)$`

Thanks for your fast response and solution. It works a treat and means that I can use the code on Titles with single and double bracketed text. Much appreciated. Cheers

---

<div class="post-metadata">

### Author: ![TersonWatt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/tersonwatt/32/12613_2.png) [@TersonWatt](https://community.mp3tag.de/u/TersonWatt)
#### Post date: [November 12, 2022, 3:16pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/8 "2022-11-12T15:16:53Z")

</div>

> [@MotleyG](#):
>
> I think this was just covered not long ago here.

Thanks for your suggestion. The solution you pointed me to strips everything that's bracketed similar to the code I was using. Cheers

---

<div class="post-metadata">

### Author: ![TersonWatt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/tersonwatt/32/12613_2.png) [@TersonWatt](https://community.mp3tag.de/u/TersonWatt)
#### Post date: [November 12, 2022, 3:28pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/10 "2022-11-12T15:28:10Z")

</div>

> [@MotleyG](#):
>
> I think this was just covered not long ago here.

Apologies, reading the thread more carefully there is a RegExp code ( `(.*)\(.*\)$` ) that also works. Thanks.

---

<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 12, 2022, 3:31pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/11 "2022-11-12T15:31:52Z")

</div>

> [@TersonWatt](#):
>
> `(.*)\(.*\)$`

As mentioned, this simpler regular expression only works for the case, where you don't have any more text after the last bracketed text.

So it would not work for  
`Escape (The Pina Colada Song) (Original 1979 7inch Single Version) another Text`  
it works fine for  
`Escape (The Pina Colada Song) (Original 1979 7inch Single Version)`  
resulting in "Escape (The Pina Colada Song)"

---

<div class="post-metadata">

### Author: ![TersonWatt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/tersonwatt/32/12613_2.png) [@TersonWatt](https://community.mp3tag.de/u/TersonWatt)
#### Post date: [November 12, 2022, 7:53pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/12 "2022-11-12T19:53:36Z")

</div>

> [@LyricsLover](#):
>
> where you don't have any more text after the last bracketed text

OK, I hadn't a tried a tag with text after the last bracketed text.

---

<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 12, 2022, 7:53pm UTC](https://community.mp3tag.de/t/regexp-required-to-remove-bracketed-text-when-there-is-two-sets-of-brackets/59050/13 "2022-12-12T19:53:45Z")

</div>

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