Quirks of Regular Expressions in Mp3tag

Hello folks,

Could someone please help me to understand the single quote marks (') sometimes used in regular expressions posted here? For example, here is one from Dano for extracting parenthesized years from file names:

$regexp(%_filename%,'^.+?\((\d{4})\)'.*?$,$1)

It works, but not without the single quote marks. Why? In other applications, the marks must be removed for such an expression to work. This is unfortunate because I like to use the Expresso expression builder to help construct expressions for Mp3tag. I have wasted time writing expressions that "should" work (and do work elsewhere) but fail in Mp3tag without the mysterious ' marks.

I have not found a reference that explains when and where to use these marks and they seem to be unique to Mp3tag. Any suggestions are welcome. Perhaps a section should be added to the script help page.

The "Regular Expression" has its own RE language and Mp3tag has its own Mp3tag Scripting language. Each language has its own special characters, which need to be escaped to use them in their literal meaning. Mp3tag parses at first its own language, then parses the RE language.
In both languages a round open bracket has a special meaning.
In MP3tag language the ( is part of the function syntax, e. g. $num(...).
In RE language the ( is part of the grouping feature, e. g. (.+?).
To escape the round bracket in RE language you have to escape it this way (
To escape resp. literalize this sequence in Mp3tag language you have to use the single apostrophe, so it can be written as '(' or '('.
To escape multiple special characters in series, the complete RE string can be literalized in one go.

$regexp(%_filename%,'^.+?\((\d{4})\).*?$',$1)

... or ...

$regexp(%_filename%,'^.+?\((\d{4})\).*?$','$1')

The usage of special characters is explained in the Mp3tag manual, but not their interaction with the Regular Expression language.

DD.20110301.0154.CET

Detlev, thank you for your very clear explanation! I had a feeling that special characters were involved but now I understand how.

If I understand this correctly, when a regular expression appears as a parameter of an Mp3Tag function, the entire parameter can be enclosed in single quote marks, whether or not it contains special characters. That follows the practice in most script languages, where strings must be differentiated from other data types. I have begun to do this, and so far my expressions are working properly.

Best regards,
Doug Mackie