editor/vim/ VimRegex101
Characters
. -- any character
[abc] -- any character in {a,b,c}
[a-z] -- any character from a-z
[A-Z] [0-9] -- other ranges for character classes
[^abc] -- any character other than {a,b,c}
\l -- lowercase letter
\L -- non lowercase letter (negation of \l)
\x -- hex digit
\X -- not hex digit
\s -- whitespace
\S -- not whitespace
\w -- word (lower, upper alphabet, numbers and underscore)
\W -- not word
\d -- numeric digit (i.e. [0-9]
\D -- not numeric digit (anything but 0-9)
\o -- octal digit
\O -- non octal digit
\p -- printable character
\P -- like \p but excluding digits
\u -- uppercase character
\U -- non uppercase character
\a -- alphabetic character
\A -- non alphabetic character
Quantifiers
x\{3} -- match xxx
x\{3,5} -- match xxx,xxxx,xxxxx
{n} -- exactly n
{n,m} -- from n to m inclusive
{n,} -- at least n
{,m} -- at most m
{} -- zero or more (same as *)
* -- zero or more
+ -- one or more
? -- zero or one
By default, quantified matches are greedy (i.e. match as much as possible). For lazy (i.e. match as little as possible)
{-n,m} {-n,} {-,m} {-n} -- basically put {- instead of {
Anchors
^ -- start of line
$ -- end of line
\<do -- word beginning with do
nut\> -- word ending with nut
^ $ \< \> -- are known as zero-width
Alternatives
hello|world -- match hello or world
Groups
6d9a28db6e13d5efab4ac759094784d6e4e9ae8068c3962723dcf9bf3072dea0e629fa6598d732768f7c726b4b621285f9c3b85303900aa912017db7617d8bdb -- capture subexpression -- use \1 \2 etc. to refer to subexpressions in replacement string
\0 -- in replacement string, the whole match
& -- does the same as \0
\%(hello\) -- non capture group
\%(hello\)\{2,3} -- match hellohello or hellohellohello
Look-arounds
foo\zebar -- match "foo" provided it is followed by "bar"
foo\%(bar\)\@= -- does the same
foo\zsbar -- match "bar" provided it is preceded by "foo"
\%(foo\)\@<=bar -- does the same
-- use ! instead of = for negative lookahead and lookbehind
More
do%[nut] -- matches do don donu donut
chocolate\_sdonut -- matches chocolate followed by whitespace followed by donut, including newlines
\%^ \%$ -- start and end of file
\%V -- start within visual area