Smart append to a field

I know that you can do Format Value (%comment% + extra word) to add things, but it can't detect if the word is already there.

For instance, say I want to add "live" to a comment that already has "random words" in it, and NOT add it if the comment already contains "live".

AFAIK, this is not possible with FormatValue. I guess it takes a Regular Expression to tackle. Can anyone suggest how to do this? And what action would I use (Replace?)

Thanks smart regex'ers

Should "live" be the last word? You could use something like this as formatstring:

$ifgreater($strstr($right(%comment%,4),Live),0,%comment%,%comment% Live)

@ffolke: If the word "live" could be "anywhere" in your comment, it would be nearly impossible. Of course, one could build a regex to find "live" - but are you sure, that this "live" has no other meaning?

Whats about "live out there in the fog" or "live 8" or "live animal" - this could be tricky! :sunglasses:

It doesn't matter that it has to be the last word, just that it goes there without duplicating.

I just tried your suggestion, but it seems to add "Live" even if "Live" is present in the field somewhere (in other words it adds the word to every file).

You are correct that "live" could be anywhere within the comment, but it can't be nearly impossible? As of right now, I know for a fact there would be no instances of "live" that are in the wrong context like your example. I would, however, like to employ this technique for styles or subgenres (that I put in comments) using the AMG script. I want to mass adjust several files for keywords that I think might be missing from AMG [ws]. What I don't want to do is create extra duplicate data that contains my desired keyword.

Unfortunately, I am very poor at RE's. And I couldn't get Sebastian's FormatValue to work. I tested with several files with different orders and configurations:

This is Live
Live in Concert
Live Live
good and evil

Yet for some reason, Live was added to ALL files?!

Can someone give me some guidance? (or maybe a tutorial)

Then you did something wrong. My formatstring should work as intended (and it does since I just tested) for the following:

This is Live
Live Live

For the others it won't work since "Live" is not the last word obviously. By the way, we are talking about Format value not Regexp replace.

ok, I see, you're right. This only works if Live is at the end of the field source. I thought you meant the output would be appended to the end.

Is there any way to detect "live" anywhere in the field, so that it would add it if it was not present at all?

For instance if there was:

bootleg, live, guitar,
live, metal, alternative,
dance, pop/rock, live,
soft rock, singer/songwriter,

[each line representing a different file/same field]

The output would be that only the last one would get appended:

bootleg, live, guitar,
live, metal, alternative,
dance, pop/rock, live,
soft rock, singer/songwriter, live,

Additionally, would it be possible to include a comma with the output? Sorry to ask so much.

$ifgreater($strstr(%comment%,live),0,%comment%,%comment%',' live)

or (if you want the comma appended)

$ifgreater($strstr(%comment%,live),0,%comment%,%comment% live',')

Please notice however that Mp3tag seems to differentiate between lowercase and uppercase and unfortunately, I don't know how to turn that off. Also, notice that my formatstring will find "live" even if it's part of a word like "alive" or "blahliveblah".

Edit: Sorry for writing this in German first - I am pretty tired at the moment. :stuck_out_tongue:

Danke, Takk, Gracias, Merci, Thanks. That will suffice.

I can always run the string twice with different case. And being part of a word should not pose too much of a problem.

Actually, you can use this so that it works with "live", "LIVE", "LiVe", etc.:

$ifgreater($strstr($lower(%comment%),live),0,%comment%,%comment%',' live)

The very last "live" is the one that will be appended, so if you want to have it with an uppercase first letter, use

$ifgreater($strstr($lower(%comment%),live),0,%comment%,%comment%',' Live)

And sorry for writing in German. :blush:

Thanks a million. And German is no problem (as long as I have Google Translate).