Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Special Characters in JScript

A number of metacharacters require special treatment when trying to match them. To match these special characters, you must first escape the characters, that is, precede them with a backslash character (\). The following table lists special characters and their meanings:

Special Character

Comment

$

Matches the position at the end of an input string. If the RegExp object's Multiline property is set, $ also matches the position preceding \n or \r. To match the $ character itself, use \$.

( )

Marks the beginning and end of a subexpression. Subexpressions may be captured for later use. To match these characters, use \( and \).

*

Matches the preceding character or subexpression zero or more times. To match the * character, use \*.

+

Matches the preceding character or subexpression one or more times. To match the + character, use \+.

.

Matches any single character except the newline character \n. To match ., use \.

[ ]

Marks the beginning of a bracket expression. To match these characters, use \[ and \].

?

Matches the preceding character or subexpression zero or one time, or indicates a non-greedy quantifier. To match the ? character, use \?.

\

Marks the next character as a special character, a literal, a backreference, or an octal escape. For example, the character n matches the character n. \n matches a newline character. The sequence \\ matches \ and \( matches (.

/

Denotes the start or end of a literal regular expression. To match the / character, use \/.

^

Matches the position at the beginning of an input string except when used in a bracket expression where it negates the character set. To match the ^ character itself, use \^.

{ }

Marks the beginning of a quantifier expression. To match these characters, use \{ and \}.

|

Indicates a choice between two items. To match |, use \|.

Community Additions

ADD
Show:
© 2015 Microsoft