Character | Meaning | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
\ |
Either of the following:
|
||||||||||||
^ |
Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character. For example,
For example, |
||||||||||||
$ |
Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character. For example, |
||||||||||||
* |
Matches the preceding character 0 or more times. For example, |
||||||||||||
+ |
Matches the preceding character 1 or more times. Equivalent to {1,}. For example, |
||||||||||||
? |
Matches the preceding character 0 or 1 time. Equivalent to {0,1}. For example, If used immediately after any of the quantifiers Also used in lookahead assertions, described under x(?=y) and x(?!y) in this table. |
||||||||||||
. |
(The decimal point) matches any single character except the newline character. For example, |
||||||||||||
(x) |
Matches 'x' and remembers the match. These are called capturing parentheses. For example, |
||||||||||||
(?:x) |
Matches 'x' but does not remember the match. These are called non-capturing parentheses. The matched substring can not be recalled from the resulting array's elements [1] , ..., [n] . |
||||||||||||
x(?=y) |
Matches 'x' only if 'x' is followed by 'y'. This is called a lookahead. For example, |
||||||||||||
x(?!y) |
Matches 'x' only if 'x' is not followed by 'y'. This is called a negated lookahead. For example, |
||||||||||||
x|y |
Matches either 'x' or 'y'. For example, |
||||||||||||
{n} |
Where For example, |
||||||||||||
{n,m} |
Where For example, |
||||||||||||
[xyz] |
A character set. Matches any one of the enclosed characters. You can specify a range of characters by using a hyphen. Special characters (such as the dot ( For example, |
||||||||||||
[^xyz] |
A negated or complemented character set. That is, it matches anything that is not enclosed in the brackets. You can specify a range of characters by using a hyphen. Everything that works in the normal character set also works here. For example, |
||||||||||||
[\b] |
Matches a backspace (U+0008). (Not to be confused with \ b .) |
||||||||||||
\b |
Matches a word boundary. A word boundary matches the position where a word character is not followed or preceeded by another word-character. Note that a matched word boundary is not included in the match. In other words, the length of a matched word boundary is zero. (Not to be confused with Examples: |
||||||||||||
\B |
Matches a non-word boundary. This matches a position where the previous and next character are of the same type: Either both must be words, or both must be non-words. The beginning and end of a string are considered non-words. For example, |
||||||||||||
\cX |
Where X is a character ranging from A to Z. Matches a control character in a string. For example, |
||||||||||||
\d |
Matches a digit character. Equivalent to For example, |
||||||||||||
\D |
Matches any non-digit character. Equivalent to For example, |
||||||||||||
\f |
Matches a form feed (U+000C). | ||||||||||||
\n |
Matches a line feed (U+000A). | ||||||||||||
\r |
Matches a carriage return (U+000D). | ||||||||||||
\s |
Matches a single white space character, including space, tab, form feed, line feed. Equivalent to For example, |
||||||||||||
\S |
Matches a single character other than white space. Equivalent to For example, |
||||||||||||
\t |
Matches a tab (U+0009). | ||||||||||||
\v |
Matches a vertical tab (U+000B). | ||||||||||||
\w |
Matches any alphanumeric character including the underscore. Equivalent to For example, |
||||||||||||
\W |
Matches any non-word character. Equivalent to For example, |
||||||||||||
\n |
Where n is a positive integer. A back reference to the last substring matching the n parenthetical in the regular expression (counting left parentheses). For example, |
||||||||||||
\0 |
Matches a NULL (U+0000) character. Do not follow this with another digit, because \0<digits> is an octal escape sequence. |
||||||||||||
\xhh |
Matches the character with the code hh (two hexadecimal digits) | ||||||||||||
\uhhhh |
Matches the character with the code hhhh (four hexadecimal digits). | ||||||||||||
⚐⚑ |
Regular expressions have optional flags that allow for global and case insensitive searching. These flags can be used separately or together in any order, and are included as part of the regular expression.
|
||||||||||||
✎? |
The buttons on the above tabs can be dragged into any position. The edit text areas above can be resized. USAGE: Show white space |
||||||||||||
Egs |
Note, ? after a (group) makes it optional Note, {n,m} with m missing, {n,} is equivalent to m being infinite. Note, some regular expressions can take a long time to execute and cause older browsers to hang. This is a browser fault, see ReDoS. Fix by rearranging them. |
||||||||||||
☞MDN |
Mozilla Contributions: Regular Expressions Guide Use the context menu to open a hyperlink in a new tab. |