Character Classes
Operator
|
Usage
|
.
|
Any single character, including white space
|
[c 1c 2c 3]
|
Any character contained within the brackets: c 1 or c 2 or c 3
|
[^c 1c 2c 3]
|
Any character not contained within the brackets: anything but c 1 or c 2 or c 3
|
[c 1-c 2]
|
Any character in the range of c 1 through c 2
|
\s
|
Any white-space character; equivalent to [ \f\n\r\t]
|
\S
|
Any non-white-space character; equivalent to
[^ \f\n\r\t]
|
\w
|
Any alphabetic, numeric, or underscore character; equivalent to [a-zA-Z_0-9]
|
\W
|
Any character that is not alphabetic, numeric, or underscore; equivalent to [^a-zA-Z_0-9]
|
\d
|
Any numeric digit; equivalent to [0-9]
|
\D
|
Any nondigit character; equivalent to [^0-9]
|
Logical Operators
Operator
|
Usage
|
(expr)
|
Group regular expressions and capture tokens.
|
(?:expr)
|
Group regular expressions, but do not capture tokens.
|
(?>expr)
|
Group atomically.
|
(?#expr)
|
Insert a comment into the expression. Comments are ignored in matching.
|
expr 1|expr 2
|
Match expression expr 1 or expression expr 2.
|
^expr
|
Match the expression only at the beginning of the string.
|
expr$
|
Match the expression only at the end of the string.
|
\<expr
|
Match the characters when they start a word.
|
expr\>
|
Match the characters when they end a word.
|
\<expr\>
|
Match an exact word.
|
Quantifiers
Operator
|
Usage
|
?
|
Match the preceding element 0 times or 1 time. Equivalent to {0,1} .
|
*
|
Match the preceding element 0 or more times. Equivalent to {0,} .
|
+
|
Match the preceding element 1 or more times. Equivalent to {1,} .
|
{n}
|
Must match exactly n times. Equivalent to {n,n} .
|
{n,}
|
Must occur at least n times.
|
{n,m}
|
Must occur at least n times but no more than m times.
|
q?
|
Match the preceding element q times according to the guidelines stated above for lazy quantifiers, where q represents any one of the expressions shown in the top six rows of this table (e.g., {2,5}? ).
|
q+
|
Match the preceding element q times according to the guidelines stated above for possessive quantifiers, where q represents any one of the expressions shown in the top six rows of this table (e.g., {2,5}+ ).
|
Token Operators
Operator
|
Usage
|
(expr)
|
Capture in a token all characters matched by the expression within the parentheses.
|
\N
|
Match the N th token generated by this command. That is, use \1 to match the first token, \2 to match the second, and so on.
|
$N
|
Insert the match for the N th token in a replacement string. Used only by the regexprep function.
|
(?<name>expr)
|
Capture in a token all characters matched by the expression within the parentheses. Assign a name to the token.
|
\k<name>
|
Match the token referred to by name .
|
(?(tok)expr)
|
If token tok is generated, then match expression expr .
|
(?(tok)expr1| expr2)
|
If token tok is generated, then match expression expr 1. Otherwise, match expression expr 2.
|