Skip to main content

MATCH Pattern Matching

A pattern match operator.

Synopsis

string MATCH code
string MATCHES code

string MATCH string
string MATCHES string

Arguments

string Any valid string expression.
code A pattern match code, specified as a quoted string.

Description

The MATCH (or MATCHES) operator has two forms: a pattern match operation (string MATCH code) and an equality match operation (string MATCH string).

Pattern Match Operator

The MATCH (or MATCHES) operator performs a pattern match test on string resulting in a boolean value: 1=string matches code; 0=string does not match code. For a match to occur, every character of string must exactly match code. The exception to this is the null string (""), which matches all character type codes and has a length of 0.

The OCONV and OCONVS functions provide similar pattern matching support.

The following are the available code values:

Code Meaning
... Matches any number of characters of any type. This includes CHAR(250) through CHAR(255), the dynamic array delimiter characters. Also matches the null string (""). (This code is not supported for OCONV / OCONVS pattern matching.)
0X Matches any number of characters of any type. This includes CHAR(250) through CHAR(255), the dynamic array delimiter characters. Also matches the null string ("").
nX Matches exactly n number of characters of any type.
0A Matches any number of alphabetic characters. The alphabetic characters include CHAR(250) through CHAR(255), the dynamic array delimiter characters. Also matches the null string ("").
nA Matches exactly n number of alphabetic characters.
0N Matches any number of number characters, defined as the numbers 0 through 9. Number characters do not include the plus sign, minus sign, or decimal separator. Also matches the null string ("").
nN Matches exactly n number of number characters.

code characters are not case-sensitive.

You can specify multiple code characters to match complex string patterns. For example a code of "0X3A4N" matches any number of characters of any type, followed by three alphabetic characters, followed by four number characters.

The same code values can be used in an <<...>> inline prompt, to pattern match test an interactive input value. Inline prompts can be used in MVBasic statements or MultiValue command line commands. They are described in the Caché MultiValue Commands Reference.

Equality Match Operator

The MATCH (or MATCHES) operator performs an equality match test on string resulting in a boolean value: 1=string matches string; 0=string does not match string. These matches must be identical, and are case-sensitive.

The exception to string equality matching is that the characters CHAR(253) and CHAR(254) (or any string containing them) do not return an equality match. Any string match containing one of these characters returns 0. This exception is provided because these characters are dynamic array delimiter characters.

Combining Pattern and Equality Matching

You can use the MATCH (or MATCHES) operator to mix pattern match and equality match operations. An equality match string must be specified as a quoted string, and the entire match code must be a quoted string. Therefore, to combine pattern codes and equality match strings, you must use both double quotes and single quotes. For example, "'('3N') '3N'-'4N" is the pattern code for a telephone number such as (617) 123–4567. You may include single quotes within double quotes (as shown above) or double quotes within single quotes.

Multiple Patterns

Caché MVBasic does not support the use of the “}” (right curly brace) character to delimit multiple match patterns. Code from other MultiValue implementations (such as Pick and UniVerse) that uses this syntax must be changed to replace the right curly brace with the @VM (value mark) character.

The following example shows a match to multiple patterns. If a match occurs with either pattern, the THEN clause is taken:

IF F1 MATCHES "'K'...":@VM:"'V'..." THEN GOSUB 100

See Also

FeedbackOpens in a new tab