O'Reilly logo

Mastering Vim by Ruslan Osipov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Regex basics

Regular expressions work in substitution commands, as well as in search. Regex introduces special patterns that can be used to match a set of characters; for example, see the following:

  • \(c\|p\)arrot matches both carrot and parrot—the \(c\|p\) denotes either c or p.
  • \warrot\? matches carrotparrot, and even farro—the \w signifies any word character, and the t\? means that the t is optional.
  • pa.\+ot matches parrotpatriot, or even pa123ot—the .\+ denotes one or more of any character.
If you're familiar with other variations of regex, then you'll notice that unlike in many other regex flavors, most special characters need to be escaped with \ to work (the default mode for most characters is non-regex, with a few exceptions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required