Skip to main content

REGEX_SEARCH

Use the REGEX_SEARCH function to find a matching regular expression pattern in a text value. It returns the position of the first character of the match in the second text value.

Use

REGEX_SEARCH( pattern , within_text [, start_num] )
Finds a matching regular expression pattern within a text value and returns the relative position of that match.

ParameterRequiredDescription
patternYesthe regular expression to match
within_textYesthe text to search
start_numNospecifies the character at which to start the match (starting from 1)

ReturnsNumber

Examples

Locating a Reference Code in a Multi-line Field

You can use REGEX_SEARCH in an Input Mapping formula to find the starting point of a specific piece of data within a larger block of text, which can then be used by other functions like MID to extract it.

  • Scenario: A user submits a "Support Ticket" with a long description, and you need to find where the customer's "Account Code" (which always starts with "AC-" followed by four digits) begins.
  • Formula: REGEX_SEARCH("AC-\d{4}", @Trigger.out.Description)
  • Logic:
    • "AC-\d{4}": This is the regex pattern looking for the "AC-" prefix and four digits.
    • @Trigger.out.Description: This is the within_text parameter containing the user's input.
    • Result: If the description says "Please check AC-1024 immediately," the function returns 14, indicating the match starts at the 14th character.

Validation of Pattern Placement

You can use the REGEX_SEARCH function in an Output Validation formula to ensure that a specific keyword appears within a certain range of a text string.

  • Scenario: You have a "Project Subject" field, and for administrative reasons, the word "URGENT" must appear within the first 10 characters of the string if it is present at all.
  • Formula: ASSERT(REGEX_SEARCH("URGENT", this) <= 10, "If this is urgent, the word 'URGENT' must appear at the beginning of the subject line.")
  • Logic:
    • "URGENT": The pattern being searched for.
    • this: The keyword referring to the current field's value.
    • <= 10: A comparison operator checking if the starting position returned by the search is 10 or less.
    • Result: If "URGENT" is found at position 15, the condition is FALSE, and the ASSERT function triggers the error message.

Pro Tip: The function also includes an optional third parameter, start_num, which allows you to skip a certain number of characters before beginning the search. For example, REGEX_SEARCH("pattern", within_text, 5) will ignore any matches found in the first four characters.