There are a number of meta characters that require special treatment when trying to match them. To match these special characters, you must first escape them, that is, precede them with a backslash character (\).
The table below shows those special characters and their meanings. More detailed explanations are given in the following parts of the documentations.
Special Character | Comment |
$ | Matches the position at the end of an input string. If the multi-line (m) property is set, $ also matches the position preceding \n or \r. (newline or carriage return). |
( ) | Marks the beginning and end of a sub expression. Sub expressions can be captured for later use. |
* | Matches the preceding sub expression zero or more times. |
+ | Matches the preceding sub expression one or more times. |
. | Matches any single character except the newline character \n. |
[ | Marks the beginning of a bracket expression. |
? | Matches the preceding sub expression zero or one time, or indicates a "non-greedy" quantifier. |
\ | Marks the next character as a special character, a literal, a back-reference, or an octal escape. |
^ | Matches the position at the beginning of an input string except when used in a bracket expression where it negates the character set. If the multi-line property is set, ^ also matches the position following \n or \r (newline or carriage return). |
{ | Marks the beginning of a quantifier expression. |
| | Indicates a choice between two items (or). |
To match any of these characters themselves, they must be preceded with \:
Expression | Matches |
\$ | $ |
\( | ( |
\) | ) |
\* | * |
\+ | + |
\. | . |
\[ | [ |
\? | ? |
\\ | \ |
\^ | ^ |
\{ | { |
\| | | |
/Forsta\?/matches the string "Forsta?"