Skip to main content

ARRAY_FIND

Tom Williams avatar
Written by Tom Williams
Updated this week

Type: Function

Function: ARRAY_FIND

Syntax: ARRAY_FIND(list, "regex1","regex2","regex3")

Description: Returns the first value in a given list that matches the chosen list of regexes. This function is useful to reduce a list of keywords to a single keyword based on an order of precedence.

Example use case:
Your team uses three different labels on pull requests: bug, enhancement, and security. Each pull request can have one or multiple labels attached to them but in your report, you want to surface only the most important label. You decide that security is more important than bug which itself is more important than enhancement (this is your order of precedence).

In your insight, you can create a dimension using the following custom formula to cover this type of grouping: ARRAY_FIND(label_names, "security", "bug", “enhancement”)

Sample usage:

  • ARRAY_FIND(label_names, "bug-minor", "bug-critical") will first attempt to find and return "bug-minor" from the field label_names, then will attempt to find and return "bug-critical" and eventually returns null if none of these values are contained in the field

  • ARRAY_FIND(["bug","enhancement", "security"], "security ", "bug", "enhancement") returns "security"

  • ARRAY_FIND(["bug","enhancement", "Security"], "security ", "bug", "enhancement") returns "Security" since regex matching is case-insensitive.

  • ARRAY_FIND(["bug","enhancement", "Security"], "(?c)security ", "bug", "enhancement") returns "bug" since we explicity requested case-sensitive matching for security ((?c)), which therefore skips Security.

  • ARRAY_FIND(["bug","enhancement"], "security ", "bug", "enhancement") returns "bug"

  • ARRAY_FIND(["bug-p0", "bug","enhancement"], "security ", "bug", "enhancement") returns "bug-p0" since bug matches the first element.

  • ARRAY_FIND(["bug-p0", "bug","enhancement"], "security ", "^bug$", "enhancement") returns "bug" since we used whole-word matching (^ and $)

Did this answer your question?