The match relational operator tests a string and determines if it matches a predefined pattern of alphabetical, numeric, wildcard, or literal characters.
Syntax
str.exp1 match str.exp2 |
Synonym(s)
matches |
Parameter(s)
str.exp1 |
String to test. |
|
str.exp2 |
A composite of literals and/or match operators, appended to length specifications. String operators are: |
|
ma |
Accepts only m alphabetical characters. No spaces allowed |
|
mn |
Accepts only m numeric characters. (+,- and . are not considered numeric.) |
|
mx |
Accepts m wildcards (any character). |
|
literal |
Accepts any literal string enclosed in single quotation marks. |
When combinations of match strings and literals are present, the entire match string must be enclosed in double quotation marks. The m parameter, which specifies the length of the match operator string, if 0 (zero) will match 0 or more of the specified match operator. This means that the null string will match any 0 length pattern match.
Description
The match operator compares a string value to a predefined pattern and evaluates to 1 (true) or 0 (false).
The iconv() function, using the p (pattern match) processing code, provides similar functionality to the match operator. The difference is that iconv() can perform multiple pattern matches at once, where the match requires multiple statements.
NOTE |
The results of a nondeterministic match operator are undefined and should be avoided. For instance, if response matches ’0na’. |
Example(s)
This statement takes the then path if the answer is 3 numerics.
if answer matches "3n" then print "ok" |
This checks that the value of the variable soc.sec.num has the pattern of 3 numerics,- , 2 numerics,- , and 4 numerics.
if soc.sec.num matches "3n’-’2n’-’4n" then... |
The then clause is taken if response is not any number of numerics.
if not(response matches "0n") then... |
This accepts any length of numerics, a comma, any length of numerics, a comma, and any length of numerics.
if response = "0n’,’0n’,’0n" then... |
See Also
alpha() Function, case Statement, iconv() Function, if Statement, ifr Statement, num() Function, p (Pattern Match) Processing Code, then Clause, then/else Statement Blocks