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:
Pattern | Description |
---|---|
0 to 9 | Itself |
a to z | Itself |
A to Z | Itself |
\$ | 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 (^) |
\d | Any digit character as per [0-9] |
\D | Any non-digit character as per [^0-9] |
\f | A form feed |
\n | A newline |
\r | A carriage return |
\S | A non space character |
\s | A space character |
\t | A tab character |
\v | A vertical tab |
\w | An alphanumeric character and underscore as per [0-9a-zA-Z_] |
\W | An 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 (}) |
\nnn | The ASCII character encoded by the octal value nnn |
\onnn | The ASCII character encoded by the octal value nnn |
\uhhhh | The Unicode character encoded by the hexadecimal value hhhh |
\xhh | The 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 \9 | The 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.
ECMA 262 edition 3 - section - 15.10.1
ECMA 262 edition 3 - section - 15.10.2.2
ECMA 262 edition 3 - section - 15.10.2.10
ECMA 262 edition 3 - section - 15.10.2.11
Prev | Home | Next |
RegExp pattern - character class | Up | RegExp pattern - extension syntax |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |