PWB uses the following non-UNIX regular-expression syntax:
Table A.8 Non-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 a1a but not aBBBa. |
^ | 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-Z*] matches any alphabetic character or asterisk, and [abc] matches a single a, b, or c. |
[~class] | Inverse of character class: matches any single character not in the class. For example, [~0-9] matches any character that is not a digit. |
x* | Minimal matching: matches zero or more occurrences of x, where x is a single character or a grouped expression. For example, the expression ba*b matches baaab, bab, and bb. |
x+ | Minimal matching plus (shorthand for xx*): matches one or more occurrences of x. For example, the expression ba+b matches baab and bab but not bb. |
x@ | Maximal matching: identical to x*, except that it matches as many occurrences as possible. |
x# | Maximal matching plus: identical to x+, except that it matches as many occurrences as possible. |
(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, the expression (ww!xx!xxyy)zz matches xxzz on the second alternative and xxyyzz on the third. |
(x) | Grouping. Groups an expression so that you can use a repeat operator with the expression. For example, the expression (Test)+ matches Test and TestTest. |
~x | “NOT” function: matches nothing but checks to see if the text matches x at this point and fails if it does. For example, ^~(if!while)?*$ matches all lines that do not begin with if or while. |
x^n | Power function: matches n copies of x. For example, w^4 matches wwww, and (a?)^3 matches a#aba5. |
{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 | Reference to text matched by a tagged expression. The specific substring is indicated by n. The first tagged substring is indicated as $1, the second as $2, and so on. A $0 represents the entire match. |
:e | Predefined regular expression, where e is a letter that specifies the regular expression. |
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).
Regular expressions are most powerful when they are used together. For example, the combination of the wildcard (?) and repeat (*) operators
?*
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.