Problem with Sets in $regexp


#1

I'm having a problem with $regexp when I use a set (e.g. "[\w\s]" or "[^\]") in a regular expression.

My music is structured with the genre as the 2nd directory after root
e.g. S:\Tom\Rock\Genesis etc\Mike & The Mechanics\1990 Interview\01 Mike Rutherford.mp3

I've set up an action group with a Format Value entry, Field GENRE,
Format String: $regexp(%_folderpath%,^.{3}\w+\(\w+)\.+$,$1)

This works correctly, returning 'Rock', but it only handles single words in the first directory name. When I change it to
"$regexp(%_folderpath%,^.{3}[\w\s]+\(\w+)\.+$,$1)" it returns the complete %_folderpath%

The preferable solution "$regexp(%_folderpath%,^.{3}[^\]+\(\w+)\.+$,$1)" also returns the complete %_folderpath%

Am I doing something wrong or is there a bug?

TIA


#2

Hmm, yes, please study the Mp3tag scripting language in detail, to get to know the exceptions.
Some characters are designed to have a special meaning, e. g. the square brackets.
They need to be escaped when they should be used in their literal meaning in a subsequent language like the Regular Expression Language.

$regexp(%_folderpath%,'^[A-Z]:\\(.+?)\\(.+?)\\.*$','$2') $regexp(%_folderpath%,'^..\\(.+?)\\(.+?)\\.*$','$2') $regexp(%_folderpath%,'^..\\.+?\\(.+?)\\.*$','$1')

Each regular expression returns the second foldername from the left side.

DD.20110602.0822.CEST


#3

Ah yes, the single quotes. When searching the forums I'd seen these in other replies but I hadn't realised their significance.

Many thanks for your response.