June 2024
Character Classes | Description |
---|---|
[abc] | a single character of a, b or c |
[^abc] | a character except a, b or c |
[a-z] | a character in the range a-z |
[^a-z] | a character not in range a-z |
[a-zA-Z] | a character in the range of a-z or A-Z |
Quantifiers | Description |
---|---|
a? | zero or one of a |
a* | zero or more of a |
a+ | one or more of a |
a{3} | Exactly 3 of a |
a{3,} | 3 or more of a |
a{3,6} | Between 3 and 6 of a |
a{3,6} | Between 3 and 6 of a |
a* | Greedy Quantifier |
a*? | Lazy Quantifier |
Meta Sequence | Description |
---|---|
. | Any single character other than newline (or including line terminators with the /s flag) |
a|b | alternate - match a or b |
\s | Matches any space, tab or newline character |
\S | Matches anything other than a space, tab or newline |
\d | Matches any decimal digit. Equivalent to [0-9] |
\D | Matches anything other than a decimal/digit |
\w | Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_] |
\W | Matches anything other than a letter, digit or underscore. Equivalent to [^a-zA-Z0-9_] |
Anchors | Description |
---|---|
\b | a word boundary |
\B | non word boundary |
^ | start of a string |
$ | end of a string |