Problem with closing parenthesis in $regexp

I am writing a script to move the "Featuring XYZ" over to the artist tag from the title, and I have the following.

$if($neql($strstr(%title%,'('Featuring ),0),%artist% $regexp(%title%,.*\((Featuring .*?)\).*,\1),%artist%)

This works, but it took me a while to get to it, the reason being that I did not initially include the escaped parenthesis before the "Featuring" bit. Originally I had the following:

$if($neql($strstr(%title%,'('Featuring ),0),%artist% $regexp(%title%,.*(Featuring .*?)\).*,\1),%artist%)

You'll notice the only difference between these is the missing "(" just prior to the "Featuring". Without this, I get the following error: "Found a closing ) with no corresponding opening parenthesis." The error message suggests that it is parsing this as if it were a part of the scripting function rather than an escaped part of the $regexp expression. The opening parenthesis should be unnecessary, since it is covered by the wildcard, but it is necessary to prevent this error.

Might want to check into this to save a lot of people frustration down the line.

Just escape the parenthesis with ')' like you did in the $strstr function.

$if($neql($strstr(%title%,'('Featuring ),0),%artist% $regexp(%title%,.*(Featuring .*?)\')'.*,\1),%artist%)

That doesn't work in $regexp. In $regexp, it does work with the escapes as slashes (\( and \)). The problem is that it only works if there's a matching pair. This should not be required in a regular expression and suggests a problem with the parser.

My example works...
The parenthesis pair "problem" exists in any scripting function and is solved by using ' for escaping.
In the $regexp function you need to apply both regex style escaping and Mp3tag scripting escaping.

Ah... Gotcha. I didn't see that you had left the slash in there before the quoted parenthesis. That actually does fix it. Would be nice if this was stated a little more clearly in the docs.

1 Like