Some regexp issues

Hello!

I am working on automating mine mp3tag and i've just got stuck.

I want to modify my TITLE field.
It looks like this:

(feat. , & ) I want replace "&" with a colon but ONLY in the featured artists area. So I thought about sth like this:
regexp:
\(feat. (.*)\)

replace:
$caps2((feat. $regexp($1, &,\,)))

But it's not working. I need some help with that matter.

Example:
$regexp('title itself (feat. artist_1, artist_2 & artist_3)','^(.+?\s*\(.+?,\s*.+?)\s*&\s*(.+?\))$','$1, $2')
from:
title itself (feat. artist_1, artist_2 & artist_3)
to:
title itself (feat. artist_1, artist_2, artist_3)

DD.20091217.0308.CET

QUOTE (DetlevD @ Dec 17 2009, 03:09) <{POST_SNAPBACK}>
Example:
$regexp('title itself (feat. artist_1, artist_2 & artist_3)','^(.+?\s*\(.+?,\s*.+?)\s*&\s*(.+?\))$','$1, $2')
from:
title itself (feat. artist_1, artist_2 & artist_3)
to:
title itself (feat. artist_1, artist_2, artist_3)

DD.20091217.0308.CET

Thanks for the reply!

But could you explain it more clearly? I don't get it...

This is an example using a literal string as RegExp source, which has the format like your real world TITLE contents should be formatted and look like. As your question let assume you are familiar with Mp3tag actions and scripting functions, so I think you are ready to apply resp. modify the example for your own case in order to modify the TITLE tag field as you need it.
The example demonstrates how to replace the " & " with ", " but ONLY in the featured artists area on the given string format.
You are free to use an action "Format Value" together with function $regexp() or use an action "Replace using Regular Expression".

DD.20091218.1654.CET

Well. I am familiar with those actions/scripting functions which are covered by the official manual and therefore I don't understand some parts of your tip.

So here are questions to let you guide me:

  1. Is it written to use with "Format value" or with "Replace with regular expression"? I guess, with the first one. Am I right?

  2. This is how I understand the idea of $regexp() function (divided to make it clear)

    $regexp(
    , // PART 1
    , // PART 2
    // PART 3
    )

Thus...

$regexp(                                     
'title itself (feat. artist_1, artist_2 & artist_3)',    //  PART 1
'^(.+?\s*\(.+?,\s*.+?)\s*&\s*(.+?\))$',            //  PART 2
'$1, $2'                                                          //  PART 3
)

Why every part of a function is between -> ' ' (?!)
And btw... Why mp3tag sometimes want us to use "/" and sometimes -> ' ' to output raw text?

PART 1:
If it is thus it must be valid for EVERY %title%. Not just particular one, right? I wouldn't make function just to edit single song! The number of featured artist also varies (I mentioned 3 as an example), naturally sometimes there are no featured artists at all.

PART 2:
The thing is I don't understand it. Manual doesn't explain non-literals like "^", "s", "$"... No idea what's going on in this part!

PART 3:
I bet it gets clear after I understand PART 2...

Please answer in plain English. I'm not a native speaker as you might noticed :rolleyes:

Hmm, the world is bigger than the Mp3tag manual can describe.

Because I titled my answer with "Example", it should be an example, not a ready made solution.
Somewhat in the same manner, as your first given example.
My example mainly can be read as a $regexp() scripting function, which can be used e. g. within an action "Format value".
On the other hand, with little modifications, just extract the regular expression and the replacement, you might be able to use it within an action "Replace using Regular Expression".

I often use the 'apostrophe clamp' to make clear that this entire function's parameter is a literal, it can make some expressions to be read easier for the user.

Hmm, Mp3tag is an application, which makes use of different standard software techniques, e. g. window views, user dialogs, mouse handling, list view, buttons, ID3 tagging, user scriptable programming, filter concept, regular expression and much more we cannot see behind the surface.

Because the Windows user interface has become a standard usability technique, which might not be described and explained in the Mp3tag manual, so it is with Regular Expressions too.

There are some links about using of regular expressions in general:
Artist sortieren mit "The"
Study carefully.

As I understand your words and problem analysis, I think you are on a good way to become a thoughtful planning tagger. You have understood that some tag fields may have diffferent content and different formats, therefore the one for all solution cannot be achieved by a simple inquiry here on the board, it may need several concepts to handle your music collection in part of some.

DD.20091222.1946.CET

Since the last post I've learned the basics of regexp language from your links, but again.. I'm stuck.. and I need your help!

My aim - To split COMPOSER field and attribute co-producers with label "(co-prod.)", so that:

COMPOSER_1 -> COMPOSER_1
COMPOSER_1, COMPOSER_2 -> COMPOSER_1\\COMPOSER_2
COMPOSER_1, co-produced by COMPOSER_2 -> COMPOSER_1\\COMPOSER_2 (co-prod.)
COMPOSER_1, COMPOSER_2, co-produced by COMPOSER_3, COMPOSER_4 -> COMPOSER_1\\COMPOSER_2\\COMPOSER_3 (co-prod.)\\COMPOSER_4 (co-prod.)

My set:

  1. Format value -> COMPOSER
    $regexp(
    %composer%
    co-produced by (.+)',' (.+)
    $1 (co-prod.)',' $2 (co-prod.)
    )

  2. Format value -> COMPOSER
    $regexp(
    %composer%
    co-produced by (.+)
    $1 (co-prod.)
    )

  3. Action -> Split fields by separator
    ","

So this action group is limited to maximum 2 co-producers. Of course, I can add more and more regexp to make it valid for more and more co-producers but that's not the point.
I want a smart single regexp action to reach the above mentioned.
Can you help me?

Example for the fourth case.
Set filter:
%COMPOSER% MATCHES "^(.+), (.+), co-produced by (.+), (.+)$"

Use Regular Expression for example with action Format Value:
$regexp(%composer%,'^(.+), (.+), co-produced by (.+), (.+)$','$1\\\\$2\\\\$3 (co-prod.)\\\\$4 (co-prod.)')

DD.20100201.0639.CET

QUOTE (DetlevD @ Feb 1 2010, 06:39) <{POST_SNAPBACK}>
Example for the fourth case.
Set filter:
%COMPOSER% MATCHES "^(.+), (.+), co-produced by (.+), (.+)$"

Use Regular Expression for example with action Format Value:
$regexp(%composer%,'^(.+), (.+), co-produced by (.+), (.+)$','$1\\\\$2\\\\$3 (co-prod.)\\\\$4 (co-prod.)')

DD.20100201.0639.CET

Well, this is a practical solution, no doubt about it but I expected rather more universal method (if it is possible at all). As I said, some smart refexp would be nice.

Something that would replace match:
co-produced by (.+)(, .+)* \\ I really don't know if it makes sense

Can be done?

The proposal from before is so much universal as it could be for the cases it relates to.
If you want to include other cases, then you can add modified variants of this proposal to a combined "more universal" expression.

It should be easy to modify this proposal to work with three composers or with two composers, maybe with five composers as well.
By using some if-then-else logic it should be possible to get a somewhat universal solution for your personal universum.

DD.20100202.1036.CET

Okay. I understand. I was just curious if the whole thing can be done via single regexp fitting ANY number of (co-)producers.
Combinination of regexp() and $if()'s is sufficient for me.
Thank you.

I think it can be done with a single regexp. What do you pay per hour?

DD.20100202.1847.CET

I do not :rolleyes:
Must be pretty complicated..