IF_MATCH
Tom Azernour avatar
Written by Tom Azernour
Updated over a week ago

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.

Sample usage:

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

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

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

  • IF_MATCH("some_word", "^foo", 1, "^bar", 2, 10) will return 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?