Backend Engineer • Distributed Systems • Product Builder
Knowledge Base
Regex Cheat Sheet
^ start of string, $ end of string.
. matches any character, .* means zero or more of any character.
\d digit, \w word char, \s whitespace.
[abc] one character from set, [^abc] negation.
() grouping, | OR pattern.
Escape special characters when used literally.
^abc$ # exact abc
^\d+$ # digits only
^[A-Za-z]+$ # letters only
^[A-Za-z0-9_]+$ # simple username
.+@.+\..+ # simple email
(FAIL|ERROR|WARN) # one of these words
Pattern p = Pattern.compile("^\d+$");