Character | Description |
\ | Marks the following character as a special character, or a literal character, or a backreference, or an octal escape sequence. For example, “n” matches the character “n”. “\n” matches a newline character. The sequence “\\” matches “\” and “\(” matches “(”. |
^ | Matches the start of the input string. If the Multiline property of the RegExp object is set, ^ also matches after “\n” or “\r”. |
$ | Matches the end of the input string. If the Multiline property of the RegExp object is set, $ also matches before “\n” or “\r”. |
* | Matches the preceding subexpression zero or more times. For example, zo* can match “z” as well as “zoo”. * is equivalent to {,}. |
+ | Matches the preceding subexpression one or more times. For example, “zo+” can match “zo” as well as “zoo”, but not “z”. + is equivalent to {1,}. |
? | Matches the preceding subexpression zero or one time. For example, “do(es)?” can match “do” in “do” or “does”. ? is equivalent to {,1}. |
{n} | n is a non-negative integer. Matches exactly n times. For example, “o{2}” cannot match “o” in “Bob”, but can match both “o”s in “food”. |
{n,} | n is a non-negative integer. Matches at least n times. For example, “o{2,}” cannot match “o” in “Bob”, but can match all “o”s in “foooood”. “o{1,}” is equivalent to “o+”. “o{,}” is equivalent to “o*”. |
{n,m} | Both m and n are non-negative integers, with n <= m. Matches at least n but no more than m times. For example, “o{1,3}” will match the first three “o”s in “fooooood”. “o{,1}” is equivalent to “o?”. Note that there must be no spaces between the comma and the two numbers. |
? | When this character immediately follows any other quantifier (*, +, ?, {n}, {n,}, {n,m}), the match is lazy. The lazy mode matches as few characters as possible in the search string, while the default greedy mode matches as many characters as possible. For example, for the string “oooo”, “o+?” will match a single “o”, while “o+” will match all “o”s. |
. | Matches any single character except “\n”. To match any character including “\n”, use a pattern like “[.\n]”. |
(pattern) |
Matches the pattern and captures the match. The captured match can be obtained from the resulting Matches collection, using the SubMatches collection in VBScript, and using the $…$9 properties in JScript. |
(?:pattern) | Matches the pattern but does not capture the match result, meaning it is a non-capturing match and is not stored for later use. This is useful when using the alternation operator “(|)” to combine different parts of a pattern. For example, “industr(?:y|ies)” is a more concise expression than “industry|industries”. |
(?=pattern) | Positive lookahead, matches the search string at the beginning of any string that matches the pattern. This is a non-capturing match, meaning the match is not captured for later use. For example, “Windows(?=95|98|NT|2000)” can match “Windows” in “Windows2000” but not “Windows” in “Windows3.1”. Lookahead does not consume characters, meaning that after a match occurs, the search for the next match begins immediately after the last match, not after the characters included in the lookahead. |
(?!pattern) | Negative lookahead, matches the search string at the beginning of any string that does not match the pattern. This is a non-capturing match, meaning the match is not captured for later use. For example, “Windows(?!95|98|NT|2000)” can match “Windows” in “Windows3.1” but not “Windows” in “Windows2000”. Lookahead does not consume characters, meaning that after a match occurs, the search for the next match begins immediately after the last match, not after the characters included in the lookahead. |
x|y | Matches x or y. For example, “z|food” can match “z” or “food”. “(z|f)ood” matches “zood” or “food”. |
[xyz] | Character class. Matches any one of the characters contained. For example, “[abc]” can match “a” in “plain”. |
[^xyz] | Negated character class. Matches any character not contained. For example, “[^abc]” can match “p” in “plain”. |
[a-z] | Character range. Matches any character within the specified range. For example, “[a-z]” can match any lowercase letter character from “a” to “z”. |
[^a-z] | Negated character range. Matches any character not within the specified range. For example, “[^a-z]” can match any character not between “a” and “z”. |
\b | Matches a word boundary, which is the position between a word and a space. For example, “er\b” can match “er” in “never” but not “er” in “verb”. |
\B | Matches a non-word boundary. “er\B” can match “er” in “verb” but not “er” in “never”. |
\cx | Matches a control character specified by x. For example, \cM matches a Control-M or carriage return. The value of x must be one of A-Z or a-z. Otherwise, c is treated as a literal “c” character. |
\d | Matches a digit character. Equivalent to [-9]. |
\D | Matches a non-digit character. Equivalent to [^-9]. |
\f | Matches a form feed. Equivalent to \xc and \cL. |
\n | Matches a newline character. Equivalent to \xa and \cJ. |
\r | Matches a carriage return. Equivalent to \xd and \cM. |
\s | Matches any whitespace character, including space, tab, form feed, etc. Equivalent to [\f\n\r\t\v]. |
\S | Matches any non-whitespace character. Equivalent to [^\f\n\r\t\v]. |
\t | Matches a tab character. Equivalent to \x9 and \cI. |
\v | Matches a vertical tab character. Equivalent to \xb and \cK. |
\w | Matches any word character including the underscore. Equivalent to "[A-Za-z-9_]". |
\W | Matches any non-word character. Equivalent to "[^A-Za-z-9_]". |
\xn | Matches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, "\x41" matches "A". "\x041" is equivalent to "\x4&1". ASCII codes can be used in regular expressions. |
\num | Matches num, where num is a positive integer. It is a reference to the captured match. For example, "(.)\1" matches two consecutive identical characters. |
\n | Indicates an octal escape value or a backreference. If there are at least n captured subexpressions before \n, then n is a backreference. Otherwise, if n is an octal digit (-7), then n is an octal escape value. |
\nm | Indicates an octal escape value or a backreference. If there are at least nm captured subexpressions before \nm, then nm is a backreference. If there are at least n captured subexpressions before \nm, then n followed by the literal m is a backreference. If none of the previous conditions are met, and both n and m are octal digits (-7), then \nm will match the octal escape value nm. |
\nml | If n is an octal digit (-3), and both m and l are octal digits (-7), then it matches the octal escape value nml. |
\un | Matches n, where n is a Unicode character represented by four hexadecimal digits. For example, \u00A9 matches the copyright symbol (©). |