Regex Cheat Sheet - Rust
A comprehensive guide to regular expressions with patterns, examples, and explanations
Basic Metacharacters
.
Any character except newline\\
Escape character|
Alternation (OR)^
Start of string/line$
End of string/lineCharacter Classes
[abc]
Any of a, b, or c[^abc]
Not a, b, or c[a-z]
Range from a to z\\d
Digit [0-9]\\D
Non-digit [^0-9]\\w
Word character [a-zA-Z0-9_]\\W
Non-word character\\s
Whitespace\\S
Non-whitespaceQuantifiers
*
0 or more+
1 or more?
0 or 1{n}
Exactly n times{n,}
n or more times{n,m}
Between n and m times*?
Non-greedy 0 or more+?
Non-greedy 1 or more??
Non-greedy 0 or 1Groups and Capturing
(pattern)
Capturing group(?:pattern)
Non-capturing group(?P<name>pattern)
Named capturing groupFlags
(?i)
Case insensitive(?m)
Multiline mode(?s)
Dot matches newline(?x)
Extended mode (ignore whitespace)(?U)
Swap greedinessUnicode
\\p{L}
Unicode letter\\p{N}
Unicode number\\p{P}
Unicode punctuation\\p{S}
Unicode symbol\\p{Latin}
Latin script\\P{L}
Not Unicode letterWord Boundaries
\\b
Word boundary\\B
Non-word boundary\\A
Start of text\\z
End of text