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

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

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

Thanks for your instant reply.

Yes, to remove the last set of bracketed text.

I think this was just covered not long ago here.

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:

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!

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

1 Like

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

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

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)"

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

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