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 such as . or *). This behavior can be reversed by using magic mode, as we will cover below.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.71.237