matches operator
Use the matches operator to compare a string to a regular expression. Use of the like operator resembles the use of regular expressions in UNIX™ or Perl; for simpler regular expressions, see like operator.
The matches operator makes its comparison
character by character, left to right, and ends when one of the following
conditions is met:
- a character in the source string fails to match a position in the regular expression (comparison is false)
- one string ends but the other does not (comparison is false)
- both strings end (comparison is true)
Syntax

- string
- A STRING variable to compare to a regular expression.
- regEx
- A regular expression to compare string to. The regular expression can be a CHAR or MBCHAR literal or variable, or a UNICODE variable. For more information, see "Regular expression rules" in this topic.
Regular expression rules
You can include any of the following special characters in the
regular expression:
- *
- Acts as a wildcard, matching zero or more characters in the string expression
- ?
- Acts as a wildcard, matching a single character in the string expression
- [ ]
- Any one of the characters between the two brackets is valid as
a match for the next character in the string expression. For example,
the following component of a regular expression indicates that a,
b, or c is valid as a match:
[abc] - -
- Creates a range within the bracket delimiters, such that any character
within the range is valid as a match for the next character in the
string expression. For example, the following component of a regular
expression indicates that a, b, or c is valid as a match:
[a-c]The hyphen (-) has no special meaning outside of bracket delimiters.
- ^
- The caret reverses the meaning of the bracket delimiters. Any
character other than the delimited characters is valid as a match
for the next character in the string expression. For example, the
following component of a regular expression indicates that any character
other than a, b, or c is valid as a match:
[^abc]The caret has no special meaning other than in the first position within brackets.
- \
- Indicates that the next character is to be compared to a single character in the string expression. The backslash (\) is called an escape character because it causes an escape from the usual processing; the escape character is not compared to any character in the string expression. The escape character usually precedes a character that is otherwise meaningful in the regular expression, such as an asterisk (*) or a question mark (?).
Any other character in the regular expression is a literal that is compared to a single character in the source string.
Examples
The following example uses wildcards in a regular expression:
myVar01 = "abcdef";
// evaluates as TRUE
if (myVar01 matches "a?c*")
;
endThe following example shows the use of the escape character. Note
the use of doubled backslashes:
myVar01 = "ab*def";
// evaluates as TRUE
if (myVar01 matches "ab\\*[abcd][abcde][^a-e]")
;
end
The following example uses the escape keyword
to make the plus sign the escape character for the regular expression:
myVar01 = "ab*def";
// the next logical expression evaluates to "true"
if (myVar01 matches "ab+*def" escape "+")
;
end