home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeLearning the vi EditorSearch this book

9.7. Extended Regular Expressions

Extended regular expressions were introduced in Section 8.4. 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 description below, 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 the above metacharacters with a backslash in order to match them literally.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.