User Guide
Regular expression syntax 291
Character classes
You use character classes to specify a list of characters to match one position in the regular
expression. You define character classes with square brackets (
[ and ] ). For example, the
following regular expression defines a character class that matches
bag, beg, big, bog, or bug:
/b[aeiou]g/
Escape sequences in character classes
Most metacharacters and metasequences that normally have special meanings in a regular
expression do not have those same meanings inside a character class. For example, in a regular
expression, the asterisk is used for repetition, but this is not the case when the asterisk appears
in a character class. The following character class matches the asterisk literally, along with any
of the other characters listed:
/[abc*123]/
\s Matches any white-space character (a space, tab, newline, or return
character).
\S Matches any character other than a white-space character.
\t Matches the tab character.
\unnnn Matches the Unicode character with the character code specified by the
hexidecimal number
nnnn. For example, \u263a is the smiley character.
\v Matches a vertical feed character.
\w Matches a word character (A–Z, a–z, 0-9, or _). Note that \w does not
match non-English characters, such as
é, ñ, or ç.
\W Matches any character other than a word character.
\xnn Matches the character with the specified ASCII value, as defined by the
hexidecimal number
nn.
Metasequence Description