Matches a specifiedstring to an existing regular expression.
expr A regular expression describing the pattern of matching strings for comparison.
0 Indicates no match.
grep
. Using Grep is equivalent to specifying a Syntax value of 20.Egrep If nonzero, the regular expression follows the syntax used by the UNIX command
egrep
. Using Egrep is equivalent to specifying a Syntax value of 51.Exact If nonzero, the string must match the regular expression exactly.
Length Specifies a named variable in which to store the number of characters in string that match the regular expression. If Exact is used with Length, the resulting operation is equivalent to STRLEN(string).
Position If nonzero, specifies a named variable into which the position in string where the match occurred is stored. If Exact is used with Position, the position of the matched string will be zero.
If string is an array of strings, the return values of Length and Position are arrays with the same structure as string.
Syntax The regular expression syntax encoded as bits in a longword. The table in the Discussion section provides the syntax details.
NOTE: STRMATCH uses regular expressions, not wildcard characters, for pattern matching. To use STRMATCH, it is crucial that you understand regular expressions. For a detailed discussion of regular expressions, see the chapter Working with Text in the PV-WAVE Programmer's Guide.
awk
. This is equivalent to specifying a Syntax value of 35. Keywords are used so STRMATCH uses a syntax compatible with the UNIX commands grep
or egrep
; or a completely arbitrary syntax can be specified using Syntax. The following table lists information pertinent to Syntax.
x = '' & READ, 'Enter a letter or number: ', x
IF NOT STRMATCH(x, '[a-zA-Z0-9]', /Exact) THEN PRINT, 'Invalid response.'
name = 'Smith, Bill J.' IF STRMATCH(name, '^(.*), *(.*)$', reg) THEN name = reg(2) + ' ' + reg(1)
PRINT, name
Bill J. Smith
owners = ['Bill', 'Kathy', 'Janis', 'Ken'] pets = ['cat', 'rabbit', 'fish', 'dog']
w = STRMATCH(pets, 'cat|dog') PRINT, owners(WHERE(w)), Format='(A)'
Bill
Ken