# Issue with regular expression

**URL:** <https://community.mp3tag.de/t/issue-with-regular-expression/47230>\
**Category:** Support\
**Created:** [December 5, 2019, 10:29pm UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230 "2019-12-05T22:29:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)\
**Post date:** [December 5, 2019, 10:29pm UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230/1 "2019-12-05T22:29:49Z")

</div>

Hello,

I'd like to transform

` "Song title (Live) (feat. another singer & artist) "`

into

` "Song title (Live)"`

Coming from Perl, I would use

` $regexp(%title%,\s+\([^()]+\)\s*$,)`

but unfortunately it does not work 😒  
Any idea?

Best regards,  
Andreas

---

<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:** [December 6, 2019, 5:58am UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230/2 "2019-12-06T05:58:55Z")

</div>

> [@loveMusique](#):
>
> Coming from Perl

I would have a look at the help instead

> **[Replace with Regular Expression – Mp3tag Documentation](https://docs.mp3tag.de/actions/replace-regexp/)**
>
> Documentation on the Replace with Regular Expression action type that can be performed as Quick Action or as reusable workflow from Action Groups. Mp3tag is the universal Tag Editor.

This should work

`$regexp('Song title (Live) (feat. another singer & artist)','^(.*\)) \(.*$',$1)`

---

<div class="post-metadata">

**Author:** ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)\
**Post date:** [December 6, 2019, 7:57pm UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230/3 "2019-12-06T19:57:30Z")

</div>

In this case, [scripting help](https://docs.mp3tag.de/scripting) seems more relevant:

> ## Characters with special functionality
> 
> - `[...]` The contents of brackets are displayed only if at least one of the placeholders used inside the brackets has been found.
> - `'` Outputs raw text without parsing. This will output the contained string and ignore all reserved characters. If you want to output this character, please use `''`.
> - `[]$%` You have to put a single quote around these reserved characters if you want to use them unparsed.
> - `,()` These characters must only be escaped when they are inside a scripting function.

> **`$regexp(x,expr,repl)`** replaces the pattern specified by the regular expression `expr` in the string `x` by `repl`. The fourth optional parameter enables ignore case (`1`) or disables the ignore case setting (`0`). _Please note that you have to escape comma and other special characters in `expr`._

I would recommend to try a greedyness modifier instead of the negated character class:

`$regexp(%title%,\s+\(.+?\)\s*$,)`

---

<div class="post-metadata">

**Author:** ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)\
**Post date:** [December 8, 2019, 1:32pm UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230/4 "2019-12-08T13:32:53Z")

</div>

> [@Crissov](#):
>
> $regexp(%title%,\s+(.+?)\s\*$,)

Hello,

Thank you for your help so far.  
Please let me specify my issue a bit more:

I have an example with three different titles strings:  
`TITLE (Text1) (to be deleted)`  
`TITLE (Text1) (Text2) (to be deleted)`  
`TITLE (Text1) (Text2) (Text3) (to be deleted)`  
My aim is to get rid of the last pair of parens only.  
Maybe it is too naive to take a regular expression that works fine in Perl, Java, ... and try it out here.  
But when the help says: `[^abc]` alle Zeichen, ausser "a", "b" und "c"  
then I do believe it.  
And since the last parens may contain any kind of text, it is easier to say: anything but parens!  
The non-greedy expression of Crissov simply deleted all parens.  
ohrenkino' expression did what I intended to do 🙂 Thank you very much!!

Now my question: why did the expression with the negate syntax _not_ work?  
Acc. to the help text it _should_ work (as I said, tested in Perl).  
Is there a bug?

But so far I am happy with an expression deleting the last pair of parens 🙂

---

<div class="post-metadata">

**Author:** ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)\
**Post date:** [December 21, 2019, 2:55pm UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230/5 "2019-12-21T14:55:33Z")

</div>

Hello again,

I have tried it another time:  
`$regexp(%title%,'\s*\([^()]+\)\s*$',)`

Believe it or not: It now works!  
There is a tiny difference to my first attempt:  
`$regexp(%title%,\s+\([^()]+\)\s*$,)`

I left out the '

Now my world is fine again 😃 🙂 🙃 🙂 😄

---

<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:** [January 20, 2020, 2:55pm UTC](https://community.mp3tag.de/t/issue-with-regular-expression/47230/6 "2020-01-20T14:55:36Z")

</div>

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