RegExp pattern - character literal (Definition)

These are the characters that can be used in the pattern to match against themselves.


ECMAScript edition - 3

The literal characters in a regular expression denote a particular character and have no special meaning other than to match that character at the position in the string they are defined within the overall pattern.

Simple, fixed and constant patterns can be defined purely with literal characters.

The string "JavaScript" can be matched exactly and exclusively with the pattern /JavaScript/. Unless some additional information is added to the pattern description, neither /javascript/ nor /JAVASCRIPT/ will match. However, the pattern /Java/ will match strings containing both "JavaScript" and "Java".

Here is a list of the literal characters as they would be used in the pattern:

0 to 9Itself
a to zItself
A to ZItself
\$A single dollar sign ($)
\*A single asterisk (*)
\+A single plus sign (+)
\,A single comma (,)
\.A single period (.)
\/A single slash (/)
\?A single question mark (?)
\\A single backslash (\)
\^A single circumflex (^)
\dAny digit character as per [0-9]
\DAny non-digit character as per [^0-9]
\fA form feed
\nA newline
\rA carriage return
\SA non space character
\sA space character
\tA tab character
\vA vertical tab
\wAn alphanumeric character and underscore as per [0-9a-zA-Z_]
\WAn non-alphanumeric character and underscore as per [^0-9a-zA-Z_]
\|A single vertical bar (|)
\(A single opening parenthesis (()
\)A single closing parenthesis ())
\[A single opening square bracket ([)
\]A single closing square bracket (])
\{A single opening curly brace ({)
\}A single closing curly brace (})
\nnnThe ASCII character encoded by the octal value nnn
\onnnThe ASCII character encoded by the octal value nnn
\uhhhhThe Unicode character encoded by the hexadecimal value hhhh
\xhhThe ASCII character encoded by the hexadecimal value hh
\c*The control character equivalent to ^*
\c@(NUL) - Null character
\c[(ESC) - Escape
\c\(FS) - File separator (Form separator)
\c](GS) - Group separator
\c^(RS) - Record separator
\c_(US) - Unit separator
\cA(SOH) - Start of header
\cB(STX) - Start of text
\cC(ETX) - End of text
\cD(EOT) - End of transmission
\cE(ENQ) - Enquiry
\cF(ACK) - Positive acknowledge
\cG(BEL) - Alert (bell)
\cH(BS) - Backspace
\cI(HT) - Horizontal tab
\cJ(LF) - Line feed
\cK(VT) - Vertical tab
\cL(FF) - Form feed
\cM(CR) - Carriage return
\cN(SO) - Shift out
\cO(SI) - Shift in
\cP(DLE) - Data link escape
\cQ(DC1) - Device control 1 (XON)
\cR(DC2) - Device control 2 (tape on)
\cS(DC3) - Device control 3 (XOFF)
\cT(DC4) - Device control 4 (tape off)
\cU(NAK) - Negative acknowledgement
\cV(SYN) - Synchronous idle
\cW(ETB) - End of transmission block
\cX(CAN) - Cancel
\cY(EM) - End of medium
\cZ(SUB) - Substitute
\0 to \9The last remembered substring as per the $n property
[\b]A literal backspace not to be confused with a word boundary match (using the \b outside of square brackets)

It is necessary to escape the punctuation characters as they assume special meanings when used in a pattern on their own. Refer to the other RegExp topics for further details.

See also:RegExp literal, RegExp object, RegExp pattern, RegExp pattern - alternation, RegExp pattern - character class, RegExp(), Regular expression


ECMA 262 edition 3 - section - 15.10.1

ECMA 262 edition 3 - section -

ECMA 262 edition 3 - section -

ECMA 262 edition 3 - section -