Home Explore Blog CI



neovim

9th chunk of `runtime/doc/pattern.txt`
71966bf46530fd67907add92e6cdbadc0c2f04b7f49d10510000000100000fa0
 multi.  See |/multi| for an
overview.

							*/star* */\star*
*	(use \* when 'magic' is not set)
	Matches 0 or more of the preceding atom, as many as possible.
	Example  'nomagic'	matches ~
	a*	   a\*		"", "a", "aa", "aaa", etc.
	.*	   \.\*		anything, also an empty string, no end-of-line
	\_.*	   \_.\*	everything up to the end of the buffer
	\_.*END	   \_.\*END	everything up to and including the last "END"
				in the buffer

	Exception: When "*" is used at the start of the pattern or just after
	"^" it matches the star character.

	Be aware that repeating "\_." can match a lot of text and take a long
	time.  For example, "\_.*END" matches all text from the current
	position to the last occurrence of "END" in the file.  Since the "*"
	will match as many as possible, this first skips over all lines until
	the end of the file and then tries matching "END", backing up one
	character at a time.

							*/\+*
\+	Matches 1 or more of the preceding atom, as many as possible.
	Example		matches ~
	^.\+$		any non-empty line
	\s\+		white space of at least one character

							*/\=*
\=	Matches 0 or 1 of the preceding atom, as many as possible.
	Example		matches ~
	foo\=		"fo" and "foo"

							*/\?*
\?	Just like \=.  Cannot be used when searching backwards with the "?"
	command.

					*/\{* *E60* *E554* *E870*
\{n,m}	Matches n to m of the preceding atom, as many as possible
\{n}	Matches n of the preceding atom
\{n,}	Matches at least n of the preceding atom, as many as possible
\{,m}	Matches 0 to m of the preceding atom, as many as possible
\{}	Matches 0 or more of the preceding atom, as many as possible (like "*")
							*/\{-*
\{-n,m}	matches n to m of the preceding atom, as few as possible
\{-n}	matches n of the preceding atom
\{-n,}	matches at least n of the preceding atom, as few as possible
\{-,m}	matches 0 to m of the preceding atom, as few as possible
\{-}	matches 0 or more of the preceding atom, as few as possible

	n and m are positive decimal numbers or zero
								*non-greedy*
	If a "-" appears immediately after the "{", then a shortest match
	first algorithm is used (see example below).  In particular, "\{-}" is
	the same as "*" but uses the shortest match first algorithm.  BUT: A
	match that starts earlier is preferred over a shorter match: "a\{-}b"
	matches "aaab" in "xaaab".

	Example			matches ~
	ab\{2,3}c		"abbc" or "abbbc"
	a\{5}			"aaaaa"
	ab\{2,}c		"abbc", "abbbc", "abbbbc", etc.
	ab\{,3}c		"ac", "abc", "abbc" or "abbbc"
	a[bc]\{3}d		"abbbd", "abbcd", "acbcd", "acccd", etc.
	a\(bc\)\{1,2}d		"abcd" or "abcbcd"
	a[bc]\{-}[cd]		"abc" in "abcd"
	a[bc]*[cd]		"abcd" in "abcd"

	The } may optionally be preceded with a backslash: \{n,m\}.

							*/\@=*
\@=	Matches the preceding atom with zero width.
	Like "(?=pattern)" in Perl.
	Example			matches ~
	foo\(bar\)\@=		"foo" in "foobar"
	foo\(bar\)\@=foo	nothing
							*/zero-width*
	When using "\@=" (or "^", "$", "\<", "\>") no characters are included
	in the match.  These items are only used to check if a match can be
	made.  This can be tricky, because a match with following items will
	be done in the same position.  The last example above will not match
	"foobarfoo", because it tries match "foo" in the same position where
	"bar" matched.

	Note that using "\&" works the same as using "\@=": "foo\&.." is the
	same as "\(foo\)\@=..".  But using "\&" is easier, you don't need the
	parentheses.


							*/\@!*
\@!	Matches with zero width if the preceding atom does NOT match at the
	current position. |/zero-width|
	Like "(?!pattern)" in Perl.
	Example			matches ~
	foo\(bar\)\@!		any "foo" not followed by "bar"
	a.\{-}p\@!		"a", "ap", "app", "appp", etc. not immediately
				followed by a "p"
	if \(\(then\)\@!.\)*$	"if " not followed by "then"

	Using "\@!" is tricky, because there are many places where a pattern
	does not match.  "a.*p\@!" will match from an "a" to the end of the
	line, because ".*" can match all characters in the line and the "p"
	doesn't match at the end of the

Title: Vim Regular Expression Multi Items: *, +, =, ?, {n,m}, @=
Summary
This section elaborates on multi items in Vim regular expressions, including *, +, =, ?, and {n,m}, which specify the number of times a preceding atom can be matched, as well as the '@=' zero-width matching item. It covers both greedy and non-greedy matching and provides examples for each, illustrating how they affect the matching behavior.