# \[Feature Suggestion\] Regex match boolean function

**URL:** https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766
**Category:** General Discussion
**Created:** [February 3, 2020, 6:20pm UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766 "2020-02-03T18:20:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![abelcheung](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@abelcheung](https://community.mp3tag.de/u/abelcheung)
#### Post date: [February 3, 2020, 6:20pm UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766/1 "2020-02-03T18:20:40Z")

</div>

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 😁, 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. 🙂

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [February 4, 2020, 1:04pm UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766/2 "2020-02-04T13:04:43Z")

</div>

> [@abelcheung](#):
>
> `$ifmatch(string, pattern, if-true, if-false)` -- working like `$ifgreater` and `$iflonger`

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)

---

<div class="post-metadata">

### Author: ![abelcheung](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@abelcheung](https://community.mp3tag.de/u/abelcheung)
#### Post date: [February 4, 2020, 3:59pm UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766/3 "2020-02-04T15:59:20Z")

</div>

> 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.

---

<div class="post-metadata">

### Author: ![sivaram2](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sivaram2/32/7242_2.png) [@sivaram2](https://community.mp3tag.de/u/sivaram2)
#### Post date: [February 9, 2020, 5:12am UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766/4 "2020-02-09T05:12:47Z")

</div>

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. 👍

---

<div class="post-metadata">

### Author: ![sivaram2](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sivaram2/32/7242_2.png) [@sivaram2](https://community.mp3tag.de/u/sivaram2)
#### Post date: [February 9, 2020, 5:20am UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766/5 "2020-02-09T05:20:15Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [May 28, 2025, 12:29pm UTC](https://community.mp3tag.de/t/feature-suggestion-regex-match-boolean-function/47766/7 "2025-05-28T12:29:20Z")

</div>

A post was split to a new topic: [Execute regular expression only if brackets present](https://community.mp3tag.de/t/execute-regular-expression-only-if-brackets-present/68639)
