Home Explore Blog CI



neovim

15th chunk of `runtime/doc/pattern.txt`
ae0a36d5aa20f626f6a497e83a6c6b3e9791c89272f40f300000000100000fa7
 'isprint' option)	*/\p*
\P	like "\p", but excluding digits			*/\P*

NOTE: the above also work for multibyte characters.  The ones below only
match ASCII characters, as indicated by the range.

						*whitespace* *white-space*
\s	whitespace character: <Space> and <Tab>		*/\s*
\S	non-whitespace character; opposite of \s	*/\S*
\d	digit:				[0-9]		*/\d*
\D	non-digit:			[^0-9]		*/\D*
\x	hex digit:			[0-9A-Fa-f]	*/\x*
\X	non-hex digit:			[^0-9A-Fa-f]	*/\X*
\o	octal digit:			[0-7]		*/\o*
\O	non-octal digit:		[^0-7]		*/\O*
\w	word character:			[0-9A-Za-z_]	*/\w*
\W	non-word character:		[^0-9A-Za-z_]	*/\W*
\h	head of word character:		[A-Za-z_]	*/\h*
\H	non-head of word character:	[^A-Za-z_]	*/\H*
\a	alphabetic character:		[A-Za-z]	*/\a*
\A	non-alphabetic character:	[^A-Za-z]	*/\A*
\l	lowercase character:		[a-z]		*/\l*
\L	non-lowercase character:	[^a-z]		*/\L*
\u	uppercase character:		[A-Z]		*/\u*
\U	non-uppercase character:	[^A-Z]		*/\U*

	NOTE: Using the atom is faster than the [] form.

	NOTE: 'ignorecase', "\c" and "\C" are not used by character classes.

			*/\_* *E63* */\_i* */\_I* */\_k* */\_K* */\_f* */\_F*
			*/\_p* */\_P* */\_s* */\_S* */\_d* */\_D* */\_x* */\_X*
			*/\_o* */\_O* */\_w* */\_W* */\_h* */\_H* */\_a* */\_A*
			*/\_l* */\_L* */\_u* */\_U*
\_x	Where "x" is any of the characters above: The character class with
	end-of-line added
(end of character classes)

\e	matches <Esc>					*/\e*
\t	matches <Tab>					*/\t*
\r	matches <CR>					*/\r*
\b	matches <BS>					*/\b*
\n	matches an end-of-line				*/\n*
	When matching in a string instead of buffer text a literal newline
	character is matched.

~	matches the last given substitute string	*/~* */\~*

\(\)	A pattern enclosed by escaped parentheses.	*/\(* */\(\)* */\)*
	E.g., "\(^a\)" matches 'a' at the start of a line.
	There can only be nine of these.  You can use "\%(" to add more, but
	not counting it as a sub-expression.
	*E51* *E54* *E55* *E872* *E873*

\1      Matches the same string that was matched by	*/\1* *E65*
	the first sub-expression in \( and \).
	Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc.
\2      Like "\1", but uses second sub-expression,	*/\2*
   ...							*/\3*
\9      Like "\1", but uses ninth sub-expression.	*/\9*
	Note: The numbering of groups is done based on which "\(" comes first
	in the pattern (going left to right), NOT based on what is matched
	first.

\%(\)	A pattern enclosed by escaped parentheses.	*/\%(\)* */\%(* *E53*
	Just like \(\), but without counting it as a sub-expression.  This
	allows using more groups and it's a little bit faster.

x	A single character, with no special meaning, matches itself

							*/\* */\\*
\x	A backslash followed by a single character, with no special meaning,
	is reserved for future expansions

[]	(with 'nomagic': \[])		*/[]* */\[]* */\_[]* */collection* *E76*
\_[]
	A collection.  This is a sequence of characters enclosed in square
	brackets.  It matches any single character in the collection.
	Example		matches ~
	[xyz]		any 'x', 'y' or 'z'
	[a-zA-Z]$	any alphabetic character at the end of a line
	\c[a-z]$	same
	[А-яЁё]		Russian alphabet (with utf-8 and cp1251)

								*/[\n]*
	With "\_" prepended the collection also includes the end-of-line.
	The same can be done by including "\n" in the collection.  The
	end-of-line is also matched when the collection starts with "^"!  Thus
	"\_[^ab]" matches the end-of-line and any character but "a" and "b".
	This makes it Vi compatible: Without the "\_" or "\n" the collection
	does not match an end-of-line.
								*E769*
	When the ']' is not there Vim will not give an error message but
	assume no collection is used.  Useful to search for '['.  However, you
	do get E769 for internal searching.  And be aware that in a
	`:substitute` command the whole command becomes the pattern.  E.g.
	":s/[/x/" searches for "[/x" and replaces it with nothing.  It does
	not search for "[" and replaces it with "x"!

								*E944* *E945*
	If the sequence begins with "^", it matches any

Title: Vim Regex: Character Classes, Special Characters, and Collections
Summary
This section details various character classes in Vim regex, including \p, \P, \s, \S, \d, \D, \x, \X, \o, \O, \w, \W, \h, \H, \a, \A, \l, \L, \u, and \U, along with special characters like \e, \t, \r, \b, \n, and ~. It also covers the use of \(\) for grouping patterns, backreferences using \1 to \9, and collections enclosed in square brackets [] for matching sets of characters.