Learning the vi Editor

Learning the vi EditorSearch this book
Previous: 9.6 GUI InterfacesChapter 9
nvi -- New vi
Next: 9.8 Improvements for Editing
 

9.7 Extended Regular Expressions

Extended regular expressions were introduced in Section 8.4, "Extended Regular Expressions" in Chapter 8. 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.


Previous: 9.6 GUI InterfacesLearning the vi EditorNext: 9.8 Improvements for Editing
9.6 GUI InterfacesBook Index9.8 Improvements for Editing

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System