Regex Memo
Regex cheat sheet/reference.
Any character
Matches any single character except newline.
Digit
Matches any digit character (equivalent to [0-9]).
Non-digit
Matches any non-digit character (equivalent to [^0-9]).
Word character
Matches alphanumeric characters and underscore (equivalent to [a-zA-Z0-9_]).
Non-word character
Matches any character that is not a word character.
Whitespace
Matches whitespace characters including space, tab, newline.
Non-whitespace
Matches any character that is not a whitespace.
Character set
Matches any single character listed inside the brackets.
Negated character set
Matches any single character not listed inside the brackets.
Range
Matches any character in the specified range.
Beginning of line
Matches the beginning of the string or line.
End of line
Matches the end of the string or line.
Word boundary
Matches a word boundary position (between a word character and a non-word character).
Non-word boundary
Matches any position that is not a word boundary.
Zero or more
Matches the preceding element zero or more times.
One or more
Matches the preceding element one or more times.
Zero or one
Matches the preceding element zero or one time.
Exactly n times
Matches the preceding element exactly n times.
At least n times
Matches the preceding element at least n times.
Between n and m times
Matches the preceding element between n and m times.
Capturing group
Groups multiple tokens together and creates a capture group for extracting substrings.
Non-capturing group
Groups multiple tokens together without creating a capture group.
Alternation
Matches either the element before or the element after the pipe.
Positive lookahead
Asserts that the preceding element is followed by the lookahead group.
Negative lookahead
Asserts that the preceding element is not followed by the lookahead group.
Positive lookbehind
Asserts that the following element is preceded by the lookbehind group.
Negative lookbehind
Asserts that the following element is not preceded by the lookbehind group.
Global search
Retain the index of last match, allowing iterative matches across the input.
Case-insensitive search
Ignore case differences when matching letters.
Multiline search
Changes behavior of ^ and $ to match start/end of lines, not just strings.