MATCH

Syntax:

MATCH([pattern][,string][,caseopt])

Arguments:

pattern
the pattern to use for the match. The pattern may contain combinations of fixed and wild card characters (see Service Description below), and can range from zero to 256 bytes in length. It may not contain the binary zeros ('00'X). A null pattern (zero length pattern) will match only with a null string argument.
string
the target string for the pattern match. The string can be zero to 256 bytes in length. It may contain any character except '00'X.
caseopt
indicates whether case sensitive pattern matching is to be used. 'N' (the default) indicates normal, case-insensitive matching is to be used. 'C' indicates that case-sensitive matching is desired.

Module Name:

SWXMATCH

Service Description:

The MATCH function is used to compare a pattern with a string. If the pattern matches the target string, a '1' is returned. If not, a '0' is returned.

In the simplest case, the pattern contains only "fixed" characters. Fixed characters consist of the letters of the alphabet, numbers, and all other characters except the wild card characters and '00'X. Fixed characters in pattern are compared to characters in corresponding positions in string. When normal, case-insensitve matching is specified (or defaulted), the case of the characters in pattern and string is irrelevant, because the MATCH function folds both arguments to uppercase prior to comparison. When case- sensitive matching is specified, alphabetic characters must match exactly.

Wild card characters permit a single pattern to successfully match many strings. The valid wild card characters and their meanings are as follows:

*
(asterisk) indicates that zero or more characters, of any type, will match.
?
(question mark) indicates that a single character, of any type, will match.
%
(percent sign) Same as question mark.

In addition, the backslash (\) is defined as an escape character. When prefixed with the escape character, a wild card character is interpreted as a fixed character. For example, to search for a string that begins with an asterisk, you would code:

if match('\**',string) then say 'It matched!'
The first asterisk is treated as a fixed character (because of the backslash), and the second is treated as a wild card character.

Note: To make the escape character fixed, use 2 consecutive backslashes, as in "\\abc".

Returned Information:

The MATCH function returns a REXX boolean value. If string matches pattern, a '1' is returned. If not, a '0' is returned. If you CALL the MATCH function, the returned value is contained in the RESULT special variable. The RC special variable is unchanged.

Examples:

  1. say match('abc*','abcdef')    /* '1' */
    
  2. say match('abc*','abc')       /* '1' */
    
  3. say match('abc???','abcdef')  /* '1' */
    
  4. say match('abc???','abcd')    /* '0' */
    
  5. say match('*xyz','xyz')       /* '1' */
    
  6. say match('\*abc','abc')      /* '0' */
    
  7. say match('\*abc','*abc')     /* '1' */
    


© Copyright 1998 by Open Software Technologies, Inc.