$if($regexpmatch(a,b,c),x,y)


#1

What's the best coding for a $regexpmatch returning bool? My best uses $regexp and a reserved string - yuk!


#2

Please explain ... if($regexpmatch(a,b,c),x,y)
What meaning has a, b, c, x, y?

Be aware of the fact, that the Mp3tag Scripting Languages currently actually never return any boolean value to the user. Any handling of boolean result is going on internally behind the scene.
I would say it is a design error of the scripting language per se.

DD.20110507.0433.CEST


#3

Same as for $regexp and $if .


#4

I would assume he means he wishes only to determine if there's a regex match in string a, and not to use the replacement functionality of $regexp(). So, if there's a regex match in string a then x, else y. I'm not sure what c would be used for, but I'm guessing it would not be used.

I haven't played with it, but I wonder if $regexp() returns True or False depending on whether or not a match was made. If so, then it could easily be used within an $if() function. You could avoid altering a by replacing the matched text with itself.


#5

Well, I've played with it now and it does not. It always returns the altered or unaltered string, which always evaluates as FALSE.


#6

This makes no sense, because testing for a match needs no replacing.

DD.20110507.0747.CEST


#7

How do you test for a regex match in Mp3tag without also replacing? I don't see any other regex functions in the documentation. Nothing among the boolean functions.


#8

Going out from chrisjj's opening post I assumed, that he has proposed a new functionality for the Mp3tag Scripting Language, so maybe I have misunderstood his request.

Currently the function $regexp on no match returns the unchanged input string (the replacing will not really happen).
This failure case can be tested by the function $eql respectively by the function $neql (is the regexp result the same as the input or not?).
To make a decision what to do next, you can use the function $if.

DD.20110507.0838.CEST


#9

a match needs no replacing.

Good point. How about:

$if($regexpmatch(a,B),x,y)

I assumed, that you have proposed a new functionality

No. I'm simply asking "What's the best coding for a $regexpmatch returning bool?"

If I could see the best coding for $if($regexpmatch(a,B),x,y), that would answer my question. Thanks.


#10

As layed out in post #8 ... with the currently given set of scripting functions ... someone can code as following.

$if($eql('Any Text',$regexp('Any Text','^Text',)),'Match No','Match Yes')

==> 'Match No'

$if($eql('Any Text',$regexp('Any Text','Text$',)),'Match No','Match Yes')

==> 'Match Yes'

The test string 'Any Text' can be replaced by any tag-field content, for example %TITLE%.

DD.20110507.1333.CEST


#11

Thanks D. I have noted:

$if($neql(subject,$regexp(subject,pattern,)),whenmatched,whennotmatched)

for the more consistent parameter ordering.

If you can think of an improvement that avoids repeating "subject", please say!


#12

I have long subjects that is making it quite desirable to avoid this repeating of subject. Any solution?


#13

Copy it to a temporary field. Run your action containing the regex expression, then remove the temp field.


#14

Thanks, but doesn't work in Export configs.