Extended Regular Expressions

We introduced extended regular expressions earlier in the section Extended Regular Expressions. vile provides essentially the same facilities as nvi’s extended option. This includes the POSIX bracket expressions for character classes, [[:alnum::]], with some extensions (additional classes and abbreviations), and interval expressions, such as {,10}. The syntax is somewhat different from nvi, relying on additional backslash-escaped characters:

\|

Indicates alternation: house\|home.

\+

Matches one or more of the preceding regular expression.

\?

Matches zero or one of the preceding regular expression.

\(...\)

Provides grouping for *, \+, and \?, as well as making matched subtexts available in the replacement part of a substitute command (\1, \2, etc.).

\s\S

Match whitespace and nonwhitespace characters, respectively.

\w\W

Match “word-constituent” characters (alphanumerics and the underscore, “_”) and non-word-constituent characters, respectively. For example, \w\+ would match C/C++ identifiers and keywords.[66]

\d\D

Match digits and nondigits, respectively.

\p\P

Match printable and nonprintable characters, respectively. Whitespace is considered to be printable.

vile allows the escape sequences \b, \f, \r, \t, and \n to appear in the replacement part of a substitute command. They stand for backspace, form feed, carriage return, tab, and newline, respectively. Also, from the vile documentation:

Note that vile mimics perl’s handling of \u\L\1\E instead ...

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.