\ |
Marks the next character as a special character, a literal, or an octal escape. For example, n matches the character n; \n matches a new line character. The sequence \\ matches \ and \( matches (. |
^ |
Matches the position at the beginning of the input string. |
$ |
Matches the position at the end of the input string. |
* |
Matches the preceding sub-expression zero or more times. For example, zo* matches z and zoo. * is equivalent to {0,}. |
+ |
Matches the preceding sub-expression one or more times. For example, zo+ matches zo and zoo, but not z. + is equivalent to {1,}. |
? |
Matches the preceding sub-expression zero or one time. For example, do(es)? matches the do in do and does. ? is equivalent to {0,1}. |
{n} |
n is a nonnegative integer. Matches the preceding sub-expression exactly n times. For example, o{2} does not match the o in Bob, but matches the two o’s in food. |
{n,} |
n is a nonnegative integer. Matches the preceding sub-expression at least n times. For example, o{2,} does not match the o in Bob, but matches all the o’s in foooood. o{1,} is equivalent to o+. o{0,} is equivalent to o*. |
{n,m} |
m and n are nonnegative integers, where n <= m. Matches the preceding sub-expression at least n and at most m times. For example, o{1,3} matches the first three o’s in fooooood. o{0,1} is equivalent to o?. Note that there cannot be spaces between the comma and the numbers. |
? |
When this character immediately follows any of the other quantifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible. For example, in the string oooo, o+? matches a single o, while o+ matches all o’s. |
. |
Matches any single character except \n. To match any character including the \n, use a pattern such as [.\n]. |
( ) |
Groups one or more regular expressions to establish a logical regular expression consisting of sub-expressions. Used to override the standard precedence of certain operators. To match parentheses characters ( ), use \( or \). |
x|y |
Matches either x or y. For example, z|food matches z or food. (z|f)ood matches zood or food. |
[xyz] |
A character set. Matches any one of the enclosed characters. For example, [abc] matches the a in plain. |
[^xyz] |
A negative character set. Matches any character not enclosed. For example, [^abc] matches the p in plain. |
[a-z] |
A range of characters. Matches any character in the specified range. For example, [a-z] matches any lowercase alphabetical character in the range a to z. |
[^a-z] |
A negative range of characters. Matches any character not in the specified range. For example, [^a-z] matches any character not in the range a to z. |
\b |
Matches a word boundary, that is, the position between a word and a space. For example, er\b matches the er in never but not the er in verb. |
\B |
Matches a non-word boundary. For example, er\B matches the er in verb but not the er in never. |
\cx |
Matches the control character indicated by x. For example, \cM matches a Control-M or carriage return character. The value of x must be in the range of A-Z or a-z. If not, c is assumed to be a literal c character. |
\d |
Matches a digit character. Equivalent to [0-9]. |
\D |
Matches a non-digit character. Equivalent to [^0-9]. |
\s |
Matches any white space character including space, tab, form-feed, etc. Equivalent to [ \f\n\r\t\v]. |
\S |
Matches any non-white space character. Equivalent to [^ \f\n\r\t\v]. |
\w |
Matches any word character including underscore. Equivalent to [A-Za-z0-9_]. |
\W |
Matches any non-word character. Equivalent to [^A-Za-z0-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. Allows ASCII codes to be used in regular expressions. |