MATCHFIELD function

Syntax

MATCHFIELD (string, pattern, field)

Description

Use the MATCHFIELD function to check a string against a match pattern (see the MATCH operator for information about pattern matching).

field is an expression that evaluates to the portion of the match string to be returned.

If string matches pattern, the MATCHFIELD function returns the portion of string that matches the specified field in pattern. If string does not match pattern, or if string or pattern evaluates to the null value, the MATCHFIELD function returns an empty string. If field evaluates to the null value, the MATCHFIELD function fails and the program terminates with a run-time error.

pattern must contain specifiers to cover all characters contained in string. For example, the following statement returns an empty string because not all parts of string are specified in the pattern:

MATCHFIELD ("XYZ123AB", "3X3N", 1)

To achieve a positive pattern match on string above, the following statement might be used:

MATCHFIELD ("XYZ123AB", "3X3N0X", 1)

This statement returns a value of "XYZ".

Examples

Source Lines
Program Output
Q=MATCHFIELD("AA123BBB9","2A0N3A0N",3) PRINT "Q= ",Q
Q=    BBB
ADDR='20 GREEN ST. NATICK, MA.,01234' ZIP=MATCHFIELD(ADDR,"0N0X5N",3) PRINT "ZIP= ",ZIP
ZIP=   01234
INV='PART12345 BLUE AU' COL=MATCHFIELD(INV,"10X4A3X",2) PRINT "COL= ",COL
COL=   BLUE

In the following example the string does not match the pattern:

Source Lines
Program Output
XYZ=MATCHFIELD('ABCDE1234',"2N3A4N",1) PRINT "XYZ= ",XYZ
XYZ=

In the following example the entire string does not match the pattern:

Source Lines
Program Output
ABC=MATCHFIELD('1234AB',"4N1A",2) PRINT "ABC= ",ABC
ABC=