Skip to main content

IF_MATCH

Tom Williams avatar
Written by Tom Williams
Updated yesterday

Function: IF_MATCH

Syntax: IF_MATCH(target, regex1, result_if_regex1, [regex2, result_if_regex2], ..., [else_result])

Description: Evaluates the target against a list of regular expressions (regexes) and return the result value from the first matching regex. If no regexes are matched then the else_result is returned (or null if none is specified). All the result values must have the same type.

Note that matching is case-insensitive by default. You can make the regex case sensitive by adding (?c) at the beginning of your regex.

Note that backslashes (\) need to be escaped in strings. So typical regex patterns such as \d will have to be written \\d in regex strings. See the examples below.

Sample usage:

  • IF_MATCH("foo_bar", "^foo", 1, "^bar", 2) returns 1

  • IF_MATCH("bar_foo", "^foo", 1, "^bar", 2) returns 2

  • IF_MATCH("some_word", "^foo", 1, "^bar", 2) returns null, since no regexes match the target value and there are no fallback values

  • IF_MATCH("1234", "\\d+", "number", "^bar", "other") returns "number"

  • IF_MATCH("some_word", "^foo", 1, "^bar", 2, 10) returns 10, since it is the fallback value

  • IF_MATCH(label_names, "(bug|defect)", "bug", "(feat|improvement)", "feature", "other") will reduce labels (e.g. on an issue or PR) to a single keyword using regex matching.

  • IF_MATCH(sub_type, "(bug|defect)", "bug", "(feat|improvement)", "feature", "other") will regroup an issue sub-type (e.g. from Jira) into broader categories using regex matching.

Did this answer your question?