Extended Regular Expressions
We introduced extended regular expressions earlier in
the section Extended Regular Expressions. Here, we just
summarize the metacharacters that nvi provides. nvi also supports the POSIX bracket
expressions, [[:alnum:]]
, and so
on.
You use :set extended
to
enable extended regular expression matching:
|
Indicates alternation. The left and right sides need not be just single characters.
(...)
Used for grouping, to allow the application of additional regular expression operators.
When
extended
is set, text grouped with parentheses acts like text grouped in\(...\)
in regular vi; the actual text matched can be retrieved in the replacement part of a substitute command with\1
,\2
, etc. In this case,\(
represents a literal left parenthesis.+
Matches one or more of the preceding regular expressions. This is either a single character or a group of characters enclosed in parentheses.
?
Matches zero or one occurrence of the preceding regular expression.
{...}
Defines an interval expression. Interval expressions describe counted numbers of repetitions. In the following descriptions, n and m represent integer constants:
{
n
}
Matches exactly n repetitions of the previous regular expression.
{
n
,}
Matches n or more repetitions of the previous regular expression.
{
n
,
m
}
Matches n to m repetitions.
When
extended
is not set, nvi provides the same functionality with\{
and\}
.
As might be expected, when extended
is set, you should precede metacharacters with a backslash in ...
Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.