Quantifiers or multis

Each character (be it a literal or a special character) or a range of characters is followed by a quantifier, or a multi in Vim terms.

For example, w+ will match one or more word characters, and a{2,4} will match two to four a characters in succession (such as  aaa, for example).

Here is the list of most common quantifiers:

Symbol

Meaning

*

0 or more, greedy

+

1 or more, greedy

{-}

0 or more, non-greedy

? or =

0 or 1, greedy

{n,m}

n to m, greedy

{-n,m}

n to m, non-greedy

The full list of quantifiers is available through :help multi.

You may have encountered two new terms in the table given: greedy and non-greedy. Greedy search refers to trying to match as many characters as possible, while non-greedy search tries to match as few characters as possible.

For example, given a string foo2bar2, greedy regex w+2 will match foo2bar2 (as many characters as it can until encountering a final 2), while non-greedy w{-1,}2 will only match foo2.

..................Content has been hidden....................

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