REGEX_MATCH

Use the REGEX_MATCH script function to match a complete string. You can use this scripting element with regular expressions and in two different contexts:

  • :SET

    When used in the :SET or scalar context, it checks if a regular expression matches.

    The script function will return 0 if the string does not match the regular expression, and 1 + the number of sub-expressions (groups) if the string matches. For example, if the entire string matches the regular expression, and the expression has two groups, the function returns 3

  • :FILL

    When used in the :FILL context, it returns the match and the groups that matched in an array.

    When a string matches a regular expression containing sub-expressions, the first element of the array (index 1) stores the complete match. Subsequent array elements, starting from index 2, store the parts of the string that matched the sub-expressions, in the order they appear in the regular expression. For instance, if a string matches a regex with two groups, the first element holds the entire string, the second element holds the part matching the first group, and the third element holds the part matching the second group.

Syntax

REGEX_MATCH (String, Regex [, Flags])

Parameters

  • String

    Unicode character string that should be matched.

    Format: script literal or script variable

  • Regex

    Regular expression to be used.

    The regular expression use the Boost C++ Libraries syntax. For more information, see the official Boost C++ Libraries documentation.

  • Flags

    (Optional) Use flags to modify the operation. The flags available are:

    • i: Case-insensitive

      By default, the search is case sensitive.

    • n: Not match null (for example, with "\d*")

      The "*" qualifier searches for zero or more occurrences of a pattern and tries to find as many occurrences as possible. This might return zero occurrences. Setting this flag avoids that behavior.

    Flags can be combined and provided in any order. For example, if you combine flag i with flag n, you can do so using "in" or "ni", or the script variable &FLAG#. An exception is the flag "d", which can be used to specify a multi character sequence as a delimiter used to separate columns in a text.

Example 1

When used in the :SET or scalar context:

!* Input

:SET &EMAIL# = "john.smith@broadcom.com"

!* Regex

:SET &REGEX# = "(\w+)\.(\w+)@(\w+)(\.(\w+))+"

!*Check Email

:IF REGEX_MATCH(&EMAIL#, &REGEX#) <> 0

: PRINT &EMAIL# is an email address

:ENDIF

After the execution, the Activation report (ACT) displays the following:

2025-08-04 17:26:17 - U00020408 john.smith@broadcom.com is an email address

Example 2

Used in the :FILL context:

!* Input

:SET&EMAIL# = "john.smith@broadcom.com"

!* Regex

:DEFINE &NAMES#, STRING, 4

:SET &REGEX# = "(\w+)\.(\w+)@broadcom\.(net|com)"

:FILL &NAMES#[] = REGEX_MATCH(&EMAIL#, &REGEX#)

!* Output

:SET &CNT# = 1

:SET &LEN# = LENGTH(&NAMES#[])

:PRINT Array elements:

:WHILE &CNT# <= &LEN#

: SET &CNT# = FORMAT(&CNT#,"0")

: PRINT "&CNT#. (sub)match: &NAMES#[&CNT#]"

: SET &CNT# = &CNT# + 1

:ENDWHILE

After the execution, the Activation report (ACT) displays the following:

2025-08-04 17:49:21 - U00020408 Array elements:
2025-08-04 17:49:21 - U00020408 1. (sub)match: john.smith@broadcom.com
2025-08-04 17:49:21 - U00020408 2. (sub)match: john
2025-08-04 17:49:21 - U00020408 3. (sub)match: smith
2025-08-04 17:49:21 - U00020408 4. (sub)match: com

See also: