Metacharacter
Description
Example
\w
Any alphabetic, numeric, or underscore
character. For English character sets, \w
is equivalent to [a-zA-Z_0-9]
'\w*' identifies a word comprised of any
grouping of alphabetic, numeric, or underscore
characters.
\W
Any character that is not alphabetic,
numeric, or underscore. For English
character sets, \W is equivalent to [^azA-Z_0-9]
'\W*' identifies a term that is not a word
comprised of any grouping of alphabetic,
numeric, or underscore characters.
\s
Any white-space character; equivalent to
[ \f\n\r\t\v]
'\w*n\s' matches words that end with the
letter n, followed by a white-space character.
\S
Any non-white-space character;
equivalent to [^ \f\n\r\t\v]
'\d\S' matches a numeric digit followed by
any non-white-space character.
\d
Any numeric digit; equivalent to [0-9]
'\d*' matches any number of consecutive
digits.
\D
Any nondigit character; equivalent to
[^0-9]
'\w*\D\>' matches words that do not end
with a numeric digit.
\oN or \o{N}
Character of octal value N
'\o{40}' matches the space character,
defined by octal 40.
\xN or \x{N}
Character of hexadecimal value N
'\x2C' matches the comma character, defined
by hex 2C.
Character Representation
Operator
Description
\a
Alarm (beep)
\b
Backspace
\f
Form feed
\n
New line
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
\char
Any character with special meaning in regular expressions that you want to match literally
(for example, use \\ to match a single backslash)
Quantifiers
Quantifiers specify the number of times a pattern must occur in the matching text.
Quantifier
Number of Times Expression Occurs
Example
expr*
0 or more times consecutively.
'\w*' matches a word of any length.
expr?
0 times or 1 time.
'\w*(\.m)?' matches words that optionally
end with the extension .m.
2 Program Components
2-56
Précédent

- 106/1450

Suivant