The following primitive functions and variables (which are implicitly set when the program begins) return or contain values which are patterns. These may be used as a pattern in a statement or assigned to variables. More complex patterns may be built up from these primitives using concatenation and alternation operators. Any of the pattern functions can be redefined by the user. Since the pattern primitives are variables, the user can change their meaning by assigning something else to them. To obtain the original pattern primitive value, there is a keyword (variable starting with an &) which always contains the original pattern primitive value.
ABORT causes the entire pattern match to terminate and fail. ABORT is equivalent to (FENCE FAIL). If you change the value of the ABORT variable, you can restore it by assigning the &ABORT keyword to it.
alternation binary operator | returns a pattern which has two alternatives, the left side and right side. The alternatives are tried in a left to right order.
ANY(s) returns a pattern which matches exactly one character from the set of characters in the argument string s.
ARB matches the null string as its first alternative, a string of length 1 as its second, a string of length 2 as its third and so forth. It is equivalent to the recursive pattern definition:
If you change the value of the ARB variable, you can restore it by assigning the &ARB keyword to it.
ARBNO(p) returns a pattern which matches an "arbitrary number of" the argument pattern p. A precise definition is given by this recursive pattern:
Note that ARBNO(LEN(1)) matches the same thing as ARB.
BAL is a pattern which matches any non-null string which is balanced with respect to parentheses. If you change the value of the BAL variable, you can restore it by assigning the &BAL keyword to it.
BREAK(s) returns a pattern which matches any length string up to, but not including, the first character in the subject which is from the set of characters in the string s.
BREAKX(s) this function (as defined in SPITBOL) is is equivalent to:
FAIL is a pattern which always fails and causes backtracking for other alternatives in prior part of the pattern. If you change the value of the FAIL variable, you can restore it by assigning the &FAIL keyword to it.
FENCE is a pattern which matches the null string as the first alternative and as the second alternative it aborts the pattern match. Fence is equivalent to
If you change the value of the FENCE variable, you can restore it by assigning the &FENCE keyword to it.
LEN(i) returns a pattern which matches a character string of length i. LEN(1) is equivalent to ANY(&ALPHABET).
MAXARB MAXARB is initially set to &MAXARB which is similar to the pattern &ARB except that it matches the longest possible string first, decrementing its length by one character on each alternative until it reaches zero and matches the null string. It is useful when you need to find the last occurrence of something in a string. There are many situations where you would like to search from the right to left, and MAXARB helps make that much more easy or more efficient to do. For example, the following pattern match finds the last blank in a string S within the first 80 characters and splits it into two parts, or if there is no blank in the first 80 characters, splits the string at 80 characters from the start of S. This is useful in text processing when formatting a paragraph, for example, when you need to break text up at blanks such that as many words as possible will fit on each line.
NOTANY(s) returns a pattern which matches exactly one character which is not in the set of characters in the argument string s.
POS(i) returns a pattern which succeeds only if the current match position in the subject string is i. The position before the first character of the subject is 0. The position after the first character is 1, and so forth.
REM is a pattern which matches the remaining characters in the subject string after the current match position. REM is equivalent to RTAB(0). If you change the value of the REM variable, you can restore it by assigning the &REM keyword to it.
RPOS(i) returns a pattern which succeeds only if the current match position in the subject string is k-i, where k is the length of the subject string. The position before the first character of the subject is 0. The position after the first character is 1, and so forth. RPOS(0) matches the position after the last character in the subject.
RTAB(i) returns a pattern which matches all of the characters from the current match position to the position k-i, where k is the length of the subject string. The position before the first character of the subject is 0. The position after the first character is 1, and so forth. RTAB(0) is equivalent to REM. RTAB(i) is equivalent to (ARB RPOS(i)).
SPAN(s) returns a pattern which matches a maximum length non-null string of consecutive characters in the subject string which are all in the set of characters specified by string s.
SUCCEED is a pattern which consists of an infinite number of alternatives, all of which match the null string. This pattern element is really of little practical use unless you want to get a pattern match into an infinite loop. SUCCEED is equivalent to ARBNO(''). If you change the value of the SUCCEED variable, you can restore it by assigning the &SUCCEED keyword to it.
TAB(i) returns a pattern which matches all of the characters from the current match position to the position i. The position before the first character of the subject is 0. The position after the first character is 1, and so forth. TAB(i) is equivalent to (ARB POS(i)).
Prior Page, Next Page, First Page of the Minnesota SNOBOL4 Reference