A.2 UNIX Regular-Expression Syntax

PWB uses the following UNIX-style regular-expression syntax:

Table A.6 UNIX Regular-Expression Syntax

Syntax Description

\c Escape: matches a literal occurrence of the character c and ignores any special meaning of c in a regular expression. For example, the expression \? matches a question mark (?), \^ matches a caret (^), and \\ matches a backslash (\).
. Wildcard: matches any single character. For example, the expression a.a matches aaa and a0a.
^ Beginning of line. For example, the expression ^The matches the word The only when it occurs at the beginning of a line.
$ End of line. For example, the expression end$ matches the word end only when it occurs at the end of a line.
[class] Character class: matches any one character in the class. Use a dash (–) to specify a range of characters. Within a class, all characters except ^-\] are treated literally. For example, [a-zA-Z0-9] matches any character or digit, and [abc] matches a, b, or c.
[^class] Inverse of character class: matches any character not specified in the class. For example, [^0-9] matches any character that is not a digit.
x* Repeat operator: matches zero or more occurrences of x, where x is a single character, a character class, or a grouped expression. For example, the regular expression ba*b matches baaab, bab, and bb. This operator always matches as many characters as possible.
x+ Repeat operator (shorthand for xx*): matches one or more occurrences of x. For example, the regular expression ba+b matches baab and bab but not bb.
\(x\) Tagged expression: marked text, which you can refer to as \n elsewhere in the find or replacement string. Within a find string, PWB finds text that contains the previously tagged text. Within a replacement string, PWB reuses the matched text in the replacement.
\n References the characters matched by a tagged expression, where n is a one-digit number and indicates which expression. The first tagged expression is \1, the second is \2, and so on. The entire expression is represented as \0.
\{x\} Grouping. Groups a regular expression so that you can use a repeat operator on the subexpression. For example, the regular expression \{Test\}+ matches Test and TestTest.
\{x\!y\!z\} Alternation: matches one from a set of alternate patterns. The alternates are tried in left-to-right order. The next alternate is tried only when the rest of the pattern fails. For example, \{ +\!$\} matches a sequence of blanks or the end of a line.
\~x “NOT” function: matches nothing but checks to see whether the text matches x at this point and fails if it does. For example, ^\~\{ \!$\}.* matches all lines that do not begin with white space or end of line.
\:e Predefined regular expression, where e is a letter specifying the regular expression.

Examples

In PWB, to find the next occurrence of a number (a string of digits) that begins with the digit 1 or 2:

1.Execute Arg Arg (ALT+A ALT+A)

2.Type [12][0-9]*

3.Execute Psearch (F3)

The special characters in regular expression syntax are most powerful when they are used together. For example, the following combination of the wildcard (.) and repeat (*) characters

.*

matches any string of characters. This expression is useful when it is part of a larger expression, such as

B.*ing

which matches any string beginning with B and ending with ing.