|
Regular Expression Syntax
|
|
|
Char(s)
|
Description
|
Matches...
|
|
.
|
dot
|
Any single character except new line (\n).
|
|
[...]
|
character class
|
Any character listed between [ and ].
|
|
[^...]
|
negated character class
|
Any character not listed between [^ and ].
|
|
[a-x]
|
hyphen
|
Any character in the contiguous character range a through x. Matches a hyphen if
placed immediately after opening bracket '[' in character class.
|
|
\w
|
word character
|
Any word character. Equivalent to [a-zA-Z_0-9].
|
|
\W
|
non-word character
|
Any non-word character. Equivalent to [^a-zA-Z_0-9].
|
|
\s
|
white-space
|
Any white-space character. Equivalent to [\f\n\r\t\v].
|
|
\S
|
non-white-space
|
Any non-white-space character. Equivalent to [^\f\n\r\t\v].
|
|
\d
|
digit
|
Any decimal digit. Equivalent to [0-9].
|
|
\D
|
non-digit
|
Any non-decimal digit character. Equivalent to [^0-9].
|
|
Quantifiers
|
Matches previous expression...
|
|
{min,max}
|
explicit quantifier
|
<Usage:>
|
|
{n}
|
|
n times
|
|
{n,}
|
|
a minimum of n times, no maximum
|
|
{,n}
|
|
a maximum of n times, no minimum
|
|
{n,x}
|
|
a minimum of n times, maximum of x times
|
|
*
|
asterisk; star
|
0 or more times; equivalent to {0, }.
|
|
+
|
plus sign
|
1 or more times; equivalent to {1, }.
|
|
?
|
question mark
|
0 or 1 times; equivalent to {0,1}. When following another quantifier, enforces minimal
matching (match as few repeats as possible).
|
|
Anchors (positional match)
|
Matches...
|
|
^
|
carat
|
Position at the beginning of a string. In multi-line mode, position at the beginning
of a line.
|
|
$
|
dollar sign
|
Position at the end of a string. In multi-line mode, position at the end of a line.
|
|
\A
|
|
Position at the beginning of a string. Never matches after new line (\n).
|
|
\Z
|
|
Position at the end of a string. Only matches before new line (\n) if \n is the
last character in a string.
|
|
\z
|
|
Position at the end of a string. Never matches before new line (\n).
|
|
Escaped Characters
|
Matches...
|
|
\a
|
|
Bell or alarm. Equivalent to \x07.
|
|
\b
|
|
Backspace if in a character class. Equivalent to \x08. Word boundary if not in a
character class.
|
|
\e
|
|
Escape. Equivalent to \x1B.
|
|
\f
|
|
Form feed. Equivalent to \x0C.
|
|
\n
|
|
New line. Equivalent to \x0A.
|
|
\r
|
|
Carriage return. Equivalent to \x0D.
|
|
\t
|
|
Tab. Equivalent to \x09.
|
|
\v
|
|
Vertical tab. Equivalent to \x0B.
|
|
\nnn
|
|
ASCII character, where nnn is the octal character code.
|
|
\xnn
|
|
ASCII character, where nn is the hexidecimal character code.
|
|
\cA through \cZ
|
|
ASCII control characters A through Z. Equivalent to \x01 through \x1A.
|
|
\unnnn
|
|
Unicode character, where nnnn is the hexidecimal character code.
|
|
\
|
|
Preceding any non-escape character, matches the literal character. Used primarily
to match literal of metacharacters: . ^ $ [ ] ( ) | * + ? { } \
|
|
Grouping & Alternation
|
Description
|
|
(...)
|
parentheses
|
Logical grouping of part of an expression.
|
|
|
|
alternation; or; bar
|
Match either expression it separates.
|