MATCH

MATCH


MATBUILD Index Level MATCHES
Syntax string.expression1 MATCH{ES} string.expression2
Category BASIC
Type Operator, Relational
Description tests a string and determines if it matches a pre-determined pattern of alphabetic, numeric, wild card, or literal characters.

The match operator compares a string value to a predefined pattern and evaluates to 1 (true) or 0 (false).

The "string.expression2" may be a composite of literals and/or match operators, appended to length specifications. During processing, the value must be the exact length of the length specifications parameter.

String operators:

na  accept only "n" alphabetic characters.

mn  accept only "m" numeric characters.

nx  accept "n" wildcards (any character).

literal  accepts any literal string enclosed in quotes.

The "n" parameter specifies the length of the match operator string. A length specification of 0 (zero) allows a length of zero or more of the following match operator.  When combinations of matchstrings and literals are present, the entire matchstring must be enclosed in double quotes.

The character "n" tests only for decimal digits. "+", "-", and "." are NOT considered numeric.

The "iconv" function, using the pattern match ("p") processing code, provides similar functionality to the "match" or "matches" statement. The difference between the two, however, stems from the fact that "iconv" can perform multiple pattern matches at once, where the "match" or "matches" requires multiple statements.
Options
See Also THEN | ELSE statement.block CASE THEN ICONV IF NUM ALPHA p (pattern match) pattern matching statements MATCHES IFR
Example if answer matches "3n" then print "ok"

This statement takes the "then" path if the answer is 3 characters.

if soc.sec.num matches "3n'-'2n'-'4n" then...

This checks that the value of the variable "soc.sec.num" has the pattern of 3 numbers, a "-" (dash), 2 numbers, a dash, and 4 numbers.

if not(response matches "0n") then...

The "then" clause is taken if "response" is NOT zero or more numbers.

if response = "0n,0n,0n" then...

This accepts any length of numbers, a comma, any length of numbers, a comma, and any length of numbers.
Warnings The results of a non-deterministic "match" statement are undefined and should be avoided. For instance,
if response matches '0na'
Compatibility D3 7.0 AP R83
MATBUILD Index Level MATCHES