REGEX_MATCH
Use the REGEX_MATCH script function to match a complete string. You can use this script element with regular expressions in two different contexts:
-
When used in the :SET or scalar context, it checks whether a regular expression matches. The script function returns 0 if the string does not match the regular expression, and 1 plus the number of sub-expressions (groups) if the string matches. For example, if the entire string matches and the expression has two groups, the function returns 3.
-
When used in the :FILL context, it returns the match and the matched groups 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 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 holds the part matching the first group, and the third holds the part matching the second group.
Syntax
REGEX_MATCH (String, Regex [, Flags])
Parameters
| Parameter | Description | Format | Allowed Values |
|---|---|---|---|
| String | Unicode character string to be matched | Script literal or script variable | n.a. |
| Regex | Regular expression to use. The regular expression uses the Boost C++ Libraries syntax. For more information, see the official Boost C++ Libraries documentation. | Script literal or script variable | n.a. |
| Flags
(Optional) |
Use flags to modify the operation. Flags can be combined and provided in any order — for example, combine i with n as "in" or "ni", or use the script variable &FLAG#. | Script literal or script variable |
|
Examples
Example 1
Used in the :SET or scalar context:
!* Input
:SET &EMAIL# = "john.smith@broadcom.com"
!* Regex
:SET ®EX# = "(\w+)\.(\w+)@(\w+)(\.(\w+))+"
!*Check Email
:IF REGEX_MATCH(&EMAIL#, ®EX#) <> 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 ®EX# = "(\w+)\.(\w+)@broadcom\.(net|com)"
:FILL &NAMES# [] = REGEX_MATCH(&EMAIL#, ®EX#)
!* 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: