Regex cheat sheet
Special characters
- \ = Indicates that the following character should be treated specially, or "escaped"
- ^ = Batches the beginning of input
- $ = Batches the end of input
- x* = Batches the preceding item "x" 0 or more times
- x+ = Batches the preceding item "x" 1 or more times. Equivalent to {1,}
- x? = Batches the preceding item "x" 0 or 1 times
Character classes
- \w = Batches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_]
- \W = Batches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_]
- \d = Batches any digit (Arabic numeral). Equivalent to [0-9]
- \D = Batches any character that is not a digit (Arabic numeral). Equivalent to [^0-9]
- \s = Batches a single white space character, including space, tab, form feed, line feed, and other Unicode spaces
- \S = Batches a single character other than white space.