In Regular Expression (\w*|\W*) works but (.*) doesn't


#1

Hi all, I've searched the FAQs for the solution to this but to no avail so hopefully someone can throw some light on why the obvious solution doesn't work in MP3Tag.

All I'm trying to do is add the composer, found at the beginning of the filename before the first dash (-), to the Composer field. For example; extract the composer 'Albinoni' from the filename:

Albinoni-Trumpet Concerto in C (IV - Allegro)
My first attempt was to define a 'Format value' action into which I coded the following Format string:
$regexp(%_FILENAME%,^(.*)-?(.*),$1 )
This simply created the whole filename as the composer.

After many hours of research (I'm no expert on regular expressions) and lots of trial and error, in desperation I tried the following Format string:

$regexp(%_FILENAME%,^(\w*|\W*)-?(.*),$1 )
and bugger me it worked, producing the result Albinoni as required.

Surely "\w*|\W*" is just an obtuse way of writing ".*" or have I misunderstood something?????


#2

Why don't you use the converter filename - tag with a mask
%composer%-%dummy%
or, if you insist on an action a format field action that looks like this:
$left(%_filename%,$strstr('-'))


#3

Hi bacoms, I am sure, that you can find the information in the FAQ area to solve your problem.
And reading the forum posts can help too.

To solve your problem there are several ways to go.

  • use the converter "Filename - Tag"
  • use an action "Guess values"
  • use the some more sophisticated action and function which deal with regular expressions, if you know how it works. You cannot grab a regular expression from elsewhere and hope it would work anyway. You have to understand what you do.

So give this a try ...
Action "Guess values"
Source Format: %_FILENAME%
Formatstring: %COMPOSER%-%DUMMY%

... or this ...
Converter Filename - Tag:
Formatstring: %COMPOSER%-%DUMMY%

... or this ...
Action "Format value":
Field: COMPOSER
Formatstring: $regexp(%_filename%,'^(.+?)-(.+?)$','$1')

... or this ...
Action "Format value":
Field: COMPOSER
Formatstring: $regexp(%_FILENAME%,^(.?)-(.)$,$1)
(nearly the same expression as your attempt, but without the writing errors)

Good luck!

Practical usages of the "Guess Values" action can be found in the forum ...
http://www.google.de/search?q=site%3Aforum...+guess%2Bvalues

DD.20110219.2155.CET


#4

Thanks for replying. With your help I now have a better understanding of the intricacies of MP3Tag which I only use very occasionally.

P.S.1. For anyone also looking for a solution, the actual format field action that worked in my example is:
$left(%_filename%,$sub($strstr(%_filename%,'-'),1))
P.S.2. Similarly, to remove the composer (and the dash) from the filename, I used the following format action field:
$right(%_filename%,$sub($len(%_filename%),$strstr(%_filename%,'-')))


#5

Thanks for all the alternative solutions. They have helped me gain a much better understanding of the intricacies of MP3 Tag.