z/OS ISPF Edit and Edit Macros
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Regular expressions (string, string1)

z/OS ISPF Edit and Edit Macros
SC19-3621-00

A regular expression in a FIND, CHANGE, or EXCLUDE command allows you to search for a string matching a regular expression.

ISPF uses the IBM® C regcomp and regexec functions to compile and execute a regular expression specified with a FIND, CHANGE, or EXCLUDE command. These are supported by the C runtime library and the C runtime library must be available.

ISPF queries the host code page defined for your TN3270 session. If the code page is one of the following:
 00037   00871   01123   01156
 00273   00875   01140   01157
 00277   00924   01141   01158
 00278   00930   01142   01160
 00280   00933   01143   01165
 00284   00935   01144   01364
 00285   00937   01145   01371
 00290   00939   01146   01388
 00297   01025   01147   01390
 00424   01026   01148   01399
 00425   01027   01149   04971
 00500   01047   01153   05123
 00838   01112   01154   08482
 00870   01122   01155   12712
ISPF uses the IBM C setlocale function with LC_ALL to set the corresponding C locale. This is done so that the special symbols (such as square brackets) within the regular expression are correctly interpreted when the regcomp function is used to compile the regular expression.

If the TN3270 code page is not one of the listed code pages then the default C locale is used when compiling the regular expression.

The simplest form of regular expression is a string of characters with no special meaning.

The following characters do have a special meaning; they are used to form extended regular expressions:

Symbol
Description
. (period)
The period symbol matches any one character except the terminal newline character.

For example, the regular expression d.g matches "dig", "dug", and "dog", but not "dg", though it matches "dgg".

* (asterisk)
The asterisk symbol matches zero or more instances of the previous character.

For example, the regular expression he*ath matches "hath" and "heath" and (if it exists) "heeath".

? (question mark)
The question mark symbol matches zero or one instance of the previous character.

For example, the regular expression behaviou?r matches "behaviour" and "behavior".

+ (plus)
The plus symbol matches one or more instances of the previous character.

For example, the regular expression south+ern matches "southern" and "southhern", but not "soutern". (If you also wanted a match for "soutern", use south*ern as the regular expression.)

| (vertical bar)
The vertical bar symbol acts as an OR operator and matches the values to the left and right of the vertical bar.

For example, the regular expression Jack|Jill matches "Jack" and "Jill".

\ (backslash)
The backslash symbol acts as an escape sequence. Use it when you want search for a regular expression symbol. The backslash character immediately precedes the symbol in the expression.

For example, the regular expression a.\+.b matches the string "a + b".

[string]
A string within square brackets matches any one of the characters in string.

For example, the regular expression d[iu]g matches "dig" and "dug", but not "dog".

[character-character]
The hyphen symbol, within square brackets, means through. It fills in the intervening characters according to the current collating sequence. For example, [a-z] can be equivalent to [abc...xyz] or, with a different collating sequence, it can be equivalent to [aAbBcC...xXyYzZ].

For example, the regular expression m[a-z]p matches "map" and "mop", but not "m9p", since 9 is not in the range a to z.

[^string]
The caret symbol, when the first character inside square brackets, negates the following characters within the square brackets.

For example, the regular expression d[^iu]g matches "dog", but not "dig" or "dug".

{m} {m,u} {m,}
Integer values enclosed in {} indicate the number of times to apply the preceding regular expression. m is the minimum number, and u is the maximum number. {m} indicates an exact number of times to apply the regular expression. {m,u} indicates a range of instances. {m,} indicates that there is a minimum, but no maximum.

For example:

  • m[eaiy]{2}n matches "main", "mien" and "mean", but it does not match "man", because there is only one instance of the letters in the square brackets. Nor does it match "mayan", because this has three instances of the letters in the square brackets.
  • [0-9][a-z]{2,3}[0-9] matches "7ab5" and "4abc3", but not "7b5", nor "4abcd3".
  • [0-9][a-z]{2,}[0-9] matches "4ab3", "4abc3", "4abcd3", and so on, but not "4a3".
(expression)
Used to group parts of the expression into sub-expressions. This can be used to limit an operator to a sub-expression.

For example, the regular expression z/OS.((1\.1[0-3])|(2\.[1-2])) matches "z/OS® 1.13" and "z/OS 2.1".

Note: You can use the ] (right square bracket) alone within a pair of square brackets, but only if it immediately follows either the opening left square bracket or if it immediately follows [^. For example: []-] matches the ] and - characters.

Regular expressions cannot be used for string2 for a CHANGE command.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014