[Feature Suggestion] Regex match boolean function

Using $regexp(...) can be cumbersome at times, when one want to only check if a variable matches some regex pattern and use it as a boolean test. Current situation requires user to either:

  1. Use hard-to-manage scripting along the line of $if($strcmp(%var%,$regexp(%var%,'...',... (can be more annoying if additional boolean test needs to be combined)
  2. Split into several actions: First use $regexp() to generate replaced string into temporary variable, then compare it with original variable, and finally remove temporary one.

So I want to suggest a new function to simplify regex tests, with spec like one of below (up to Florian to decide which is better):

  1. $ifmatch(string, pattern, if-true, if-false) -- working like $ifgreater and $iflonger
  2. $regmatch(string, pattern) -- only produce boolean result, like $strcmp and friends

Personally I want both :grin:, first form as a simple shortcut, and 2nd form for combining multiple boolean tests.

Please pardon me if similar feature already exists -- I haven't been following mp3tag development closely. :slight_smile:

2 Likes

isn't this more or less the scripting function implemented in $if()
$if(x,y,z) if x is true, y is returned, otherwise z.
only that you can specify in what respect the expression should "match" (is it length, case, contents, part of?, arithmetic result, and so on)

isn't this more or less the scripting function implemented in $if()

That's true, in the same sense of $ifgreater and $iflonger that are shorthands for

  • $if($grtr(... and
  • $if($grtr($len(... respectively.

I'd also really like a RegEx function which didn't do replacement, but was instead an input to the existing $if function, as mentioned. My vote is on that $regmatch which you have proposed. :+1:

So I think right now, the quick and dirty workaround would be:

$if( $eql( $regexp(<input_field>, <matching_regex>, 'Yes'), 'Yes'), <value_if_true>, <value_if_false>)