Reference
.
non-newline char^
start of line$
end of line\b
word boundary\B
non-word boundary\A
start of subject\z
end of subject\d
decimal digit\D
non-decimal digit\s
whitespace\S
non-whitespace\w
word character\W
non-word character(a|z)
a or z[az]
a or z[^az]
not a or z[a-z]
a through z(foo)
capture fooa?
0 or 1 aa*
0 or more aa+
1 or more aa{3}
3 of aa{3,}
3 or more aa{3,5}
3 through 5 a
Modifiers (enable: (?a)
, disable:
(?-a)
)
u
unicodei
case insensitives
dot matches newlinem
multilinex
whitespace ignoredFor more information see the documentation for the regex crate .
Additional escapes
\h
hex digit ([0-9A-Fa-f]
)
\H
not hex digit
([^0-9A-Fa-f]
)
\e
escape control character
\K
keep text out of match\G
anchor to previous match\Z
anchor to the end of the text before any trailing newlines\O
any character including newlineCapture groups and backreferences
\1
match first capture group\2
match second capture group\{N}
match Nth capture group(?<name> exp)
capture group named name
\k<name>
match capture group
name
Lookaround
(?=exp)
look-head for exp(?!exp)
negative look-head for
exp
(?<=exp)
look-behind for exp
(?<!exp)
negative look-behind for
exp
Atomic groups
(?>exp)
no backtracking in
exp
Conditions
(?(1))
continue if first capture group
matched
(?(<name>))
continue if capture group name matched
(?(1)true|false)
if the first capture group matched then execute the
true
regex expression, else execute
false
(?(condition)true|false)
if the condition matches then execute the
true
regex expression, else execute
false
For more information see the documentation for the fancy-regex crate .