Skip to main content

REGEX_MATCH

The REGEX_MATCH function searches each item in an array for a match against a regular expression pattern. It returns the relative position (starting at 1) of the first match found, or 0 if no matches are found.

Use

REGEX_MATCH( text, pattern )
Check if text matches the specified regular expression pattern.

ParameterRequiredDescription
textYesthe text to search
patternYesthe regular expression to match

ReturnsLogical

Examples

Validating Corporate ID Formats

You can use REGEX_MATCH in an Output Validation formula to ensure that users follow a specific naming convention when entering data into a form.

  • Scenario: A company requires all "Account Numbers" to begin with the prefix "ADT" followed immediately by exactly 7 digits.
  • Formula: ASSERT(REGEX_MATCH(this, "^ADT{7}$") > 0, "Account number must start with ADT followed by 7 numbers.").
  • Logic:
    • this: Refers to the value the user is currently entering into the capture widget.
    • "^ADT{7}$": This is the regular expression pattern.
    • Result: If the user enters "ADT1234567", the function returns 1 (the position of the match). Since 1 is greater than 0, the validation evaluates to TRUE. If they enter "ABC1234567", it returns 0, triggering the ASSERT error message.

Prohibiting Specific Characters (Character Restrictions)

By combining REGEX_MATCH with the NOT function, you can create rules that prevent users from entering prohibited characters, such as spaces or symbols.

  • Scenario: A "System Username" field must not contain any spaces to prevent errors in downstream databases.
  • Formula: ASSERT(NOT(REGEX_MATCH(this, " ") > 0), "Usernames cannot contain spaces.").
  • Logic:
    • REGEX_MATCH(this, " "): This searches the input for a space character.
    • NOT(...): This function reverses the logical result.
    • Result: If a space is found, REGEX_MATCH returns a number greater than 0. The NOT function then turns that "TRUE" state into FALSE, which causes the ASSERT function to block the submission and display the error message.