The editor has a very powerful pattern matching facility which will
match the class of patterns known as regular expressions. Patterns are
used for line searches and by the Global (g) and
Substitute (s) commands. It is the editor's
pattern matching facility
that gives it flexibility in writing powerful macros. For example, the
Ctrl left and right arrow keys are implemented by a pattern
which searches for the next or previous word in your text. We will
attempt to describe the patterns accepted by the editor in a very rigorous
manner. It is assumed that option meta characters is on (m+)
during the definition of your pattern. If it is off (m-) then
the editor will only recognize the class of patterns represented by (1) and
(2) below.
- The simplest pattern is a single character. Such a pattern matches the
given character in either upper or lower case, unless option dual is
on (d+) to make the pattern matcher differentiate between
cases.
- Patterns arranged adjacently form a single pattern. For example:
/abc/ matches any string "abc".
- The character ^ (caret) specifies a pattern which matches the null string
at the beginning of the line. Thus a line search of: /^charm/
would match the string "charm" at the beginning of a line.
- The character $ specifies a pattern which matches the null string
at the end of the line. Thus a line search of: /charm$/
would match the string "charm" at the end of a line.
- The character . (dot) specifies a pattern which matches any character.
Thus a line search of: /charm./ would match the string
"charm" followed by any character on a line.
- Any pattern followed by a * defines a pattern which matches a
string of zero or more occurrences of that pattern. Thus:
/b*/ matches the strings "b", "bb",
"bbb", etc. In addition,
since *-patterns will match zero occurrences of a given pattern,
"/b*/" will also match "". The pattern matcher
will match a * construction with the longest sequence
matching the given pattern beginning in a
given column; for example, if a line contains the string "bbbbbb",
/b*/ will match all six b's as a unit, not individually.
- The construction @(number) is a pattern which matches the
null string immediately before the numberth column on the
line. Thus a line search of: @(10)charm would match the
string "charm" starting in character position ten on the line.
If number is zero or the character . (dot)
then this pattern
will match the null string before the current cursor position in the text
area.
If number is the character t then this pattern will match
the null string before the next tab stop. This can be used to turn runs
of spaces into tabs. See the Substitute (s) command.
- The construction [string] matches any one character in string
and no other. Thus: /[0123456789]/ is a pattern which will
match a single digit. Characters in the square brackets are taken
literally, without their special meanings; so /[.]/ will
match the character "." and no other. A sequence of characters may be
specified by separating the lower and upper character by a dash (-). For
example: /[a-z0-9]/ is a pattern which will match any letter or
any digit. To match a "-" you may protect it with the backslash (\)
character.
- The construction [^string] matches any one character that is
not in string. Thus: /[^^0-9]/ is a pattern which will match
any character that is not a digit.
- A null pattern (//) is equivalent to the pattern most recently
specified within the editor. This feature is convenient for searching
through a file for a particular string. For example, if you are looking
for the string "hello" you could specify: /hello/ the first
time and: // on subsequent searches. An even quicker method
of performing this task would use the F9 key to simply
re-execute your line search.
- Any character preceded by the backslash character (\) loses its special
meaning. Thus: /\\\^^\.\$/ would match the string "\^^.$".