JavaScript RegExp Patterns
RexExp Flags
Revised July 2025
Flag | Description |
---|---|
/d | Performs substring matches (new in 2022) |
/g | Performs a global match (find all) |
/i | Performs case-insensitive matching |
/m | Performs multiline matching |
/s | Allows . (dot) to match line terminator characters (new in 2018) |
/u | Enables Unicode support (new in 2015) |
/v | An upgrade to the /u flag for better Unicode support (new in 2025) |
/y | Performs a "sticky" search (new in 2015) |
RexExp Character Classes
[] | Description |
---|---|
[a] | Matches the character between the brackets |
[^a] | Matches characters different from the character between the brackets |
[abc] | Matches any of the characters between the brackets |
[^abc] | Mathes any character NOT between the brackets |
[A-Z] | Matches character in the range from A to Z |
[^A-Z] | Matches characters NOT in the range from A to Z |
[0-9] | Matches characters in the range from 0 to 9 |
[^0-9] | Mathis characters NOT in the range from 0 to 9 |
(x|y) | Matches the x or y alternatives specified |
RexExp Metacharacters
Char | Description |
---|---|
^ | Matches from beginning of a string, or the beginning of a line if the m (multiline) flag is set |
$ | Matches from the end of a string, or the end of a line if the m (multiline) flag is set |
. | Matches single (wildcard) characters, except line terminators like \n and \r |
\w | Matches word characters (alphanumeric and underscore _) |
\W | Matches non-word characters |
\d | Matches digits (0-9) |
\D | Matches non-digit characters |
\s | Matches whitespace characters like space, tab \t, and newline \n |
\S | Matches non-whitespace character |
\b | Matches from the beginning or end of a word |
\B | Matches not from the beginning or end of a word |
[\b] | Matches backspace characters |
\0 | Matches NULL characters |
\n | Matches new line characters |
\f | Matches form feed characters |
\r | Matches carriage returns characters |
\t | Matches tab characters |
\v | Matches vertical tab characters |
\p{} | Matches characters based on a given Unicode Property (new 2018) |
\P{} | Matches character NOT based on a given Unicode Property (new 2018) |
\ddd | Matches characters specified by an octal number ddd |
\xhh | Matches characters specified by a hexadecimal number hh |
\uhhhh | Matches Unicode character specified by a hexadecimal number hhhh |
RexExp Quantifiers
Quant | Description |
---|---|
n+ | Matches strings that contains at least one n |
n* | Matches strings that contains zero or more occurrences of n |
n? | Matches strings that contains zero or one occurrences of n |
n{X} | Matches strings that contains a sequence of X n's |
n{X,Y} | Matches strings that contains a sequence of X to Y n's |
n{X,} | Matches strings that contains a sequence of at least X n's |
n$ | Matches strings with n at the end of it |
^n | Matches strings with n at the beginning of it |
?=n | Matches strings that is followed by a specific string n |
?!n | Matches strings that is not followed by a specific string n |