# \[X\] Parentheses and Square Brackets Don't Work Correctly in Regexes

**URL:** <https://community.mp3tag.de/t/x-parentheses-and-square-brackets-dont-work-correctly-in-regexes/14996>\
**Category:** No Bugs\
**Created:** [August 28, 2013, 5:46pm UTC](https://community.mp3tag.de/t/x-parentheses-and-square-brackets-dont-work-correctly-in-regexes/14996 "2013-08-28T17:46:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tappers](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/c0e974/32.png) [@Tappers](https://community.mp3tag.de/u/Tappers)\
**Post date:** [August 28, 2013, 5:46pm UTC](https://community.mp3tag.de/t/x-parentheses-and-square-brackets-dont-work-correctly-in-regexes/14996/1 "2013-08-28T17:46:44Z")

</div>

(Am using Mp3tag v2.57 on Windows 7.)

According to [https://docs.mp3tag.de/actions/replace-regexp](https://docs.mp3tag.de/actions/replace-regexp) , the following characters

. | \* ? + ( ) { } [] ^ $

can be used in regular expressions by escaping them with a preceding backslash.

But while it works fine for most of the characters, it fails for parentheses and square brackets (but strangely, works for curly braces, which are also characters commonly used for grouping).

For example, in the function $regexp(), a parenthesis that leads to unbalancing, even an escaped one, will cause the expression to fail. Suppose you want to replace all opening or closing parentheses with the word "foobar"; supposedly, this should work (notice the parentheses are indeed escaped with a backslash):

$regexp(%title%,(,foobar)  
$regexp(%title%,),foobar)

but the former won't parse at all, instead giving "[SYNTAX ERROR IN FORMATTING STRING]", and the latter will parse, but is parsed incorrectly, as if that first closing parenthesis ended the $regexp function.

Similarly, these won't work

$regexp(%title%,[,foobar)  
$regexp(%title%,],foobar)

By contrast, curly braces work fine:

$regexp(%title%,{,foobar)  
$regexp(%title%,},foobar)

I was finally able to find a workaround by enclosing in single-quotes:

$regexp(%title%,'(',foobar)  
$regexp(%title%,')',foobar)

but the documentation makes no mention of how single-quotes can be used for this purpose.

Also, why do single-quotes work when double-quotes fail?

At the very least, the documentation should be updated to address these issues.

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [October 5, 2013, 6:10pm UTC](https://community.mp3tag.de/t/x-parentheses-and-square-brackets-dont-work-correctly-in-regexes/14996/2 "2013-10-05T18:10:35Z")

</div>

Please note that you're using a scripting function (i.e., $regexp()) and not the action type Replace with regular expression (for which the help topic is linked in your original post).

As noted at [https://docs.mp3tag.de/scripting](https://docs.mp3tag.de/scripting)

> [@](#):
>
> ' 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.

Kind regards  
Florian

---

<div class="post-metadata">

**Author:** ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)\
**Post date:** [December 28, 2018, 2:33pm UTC](https://community.mp3tag.de/t/x-parentheses-and-square-brackets-dont-work-correctly-in-regexes/14996/3 "2018-12-28T14:33:41Z")

</div>

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