Regex Cheat Sheet
Syntax | Description |
---|---|
* | 0 or more times |
+ | 1 or more times |
? | 1 or 0 times |
{m} | exactly m times |
{m,} | m or more times |
{m,n} | m to n times (both inclusive) |
\n | new line |
[…] | range or character class (e.g. [a-z0-9] all lowercases and digits) |
[^…] | not in range or negated character class (e.g. [^0-9a-z] everything but 0-9 and lower case characters) |
. | Any character except newline |
\w | Word character [a-zA-Z0-9_] |
\W | Non-word character [^a-zA-Z0-9_] |
\d | Digit character [0-9] |
\D | Non-digit character [^0-9] |
\s | Whitespace character [\n\r\f\t] |
\S | Non-whitespace character [^\n\r\f\t] |
^ | The start of the line of text |
$ | The end of the line of text. (e.g. [1]$ match an all-digit-and-dash string) |
\b | Word boundary |
\B | Not-word-boundary |
i | Case-insensitive matching m ^ and $ match next to embedded \n |
(…) | Group subpattern and capture submatch into \1, \2, .. |
\n | Contains the result of nth earlier submatch from a parentheses capture group, or a named capture group |
0-9- ↩︎
Ref: