Regular Expression Pattern Matching
[ (opening
square
bracket)
Starts a character class. A character class matches a
single character out of all of the possibilities offered
by the character class. Inside a character class,
different rules apply. The rules in this section are
only valid inside character classes. The rules outside
this section are not valid in character classes, except
\n, \r, \t and \xFF
Any character
except ^,-,],\
add that
character to
the possible
matches for
the character
class.
All characters except the listed special characters.
[abc]
matches a,
b or c
\ (backslash)
followed by
any of ^,-,],\
A backslash escapes special characters to suppress
their special meaning.
[\^\]]
matches ^
or ]
- (hyphen)
except
immediately
after the
opening [
Specifies a range of characters. (Specifies a hyphen if
placed immediately after the opening [)
[a-zA-Z0-9]
matches
any letter
or digit
^ (caret)
immediately
after the
opening [
Negates the character class, causing it to match a
single character not listed in the character class.
(Specifies a caret if placed anywhere except after the
opening [)
[^a-d]
matches x
(any
character
except a, b,
c or d)
362