Java Reference
In-Depth Information
character
exaMples
function
/l{2,}/
matches
ll
in “
still
” and
lll
in “
stilllife
.”
Matches
n
or more instances of the
preceding character (where
n
is a
positive integer).
{n,}
/l{1,2}/
matches
l
in “
life
,”
ll
in “
still
,” and the first two
l
is in
“
stilllife
.”
Matches between
n
and
m
instances
of the preceding character (where
n
and
m
are positive integers).
{n,m}
[ab]
matches
a
and
b
;
[a‐c]
matches
a
,
b
and
c
.
Matches any one of the characters
in the square brackets. A range of
characters in the alphabet can be
matched using a hyphen.
[xyz]
[^aeiouy]
matches
s
in
“
easy
”;
[^a‐y]
matches
z
in “
lazy
.”
Matches any character except those
enclosed in the square brackets. A
range of characters in the alphabet
can be specified using a hyphen.
[^xyz]
Matches a backspace.
[\b]
/t\b/
matches the first
t
in
“
about time
.”
Matches a word boundary (for
example, a space or the end of a
line).
\b
/t\Bi/
matches
ti
in “
it is time
.”
Matches when there is no word
boundary in this position.
\B
/\cA/
matches Ctrl+A.
Matches a control character.
\cX
/IE\d/
matches
IE4
,
IE5
, etc.
Matches a digit character. This is
identical to
[0‐9]
.
\d
/\D/
matches the decimal point in
“
3.142
.”
Matches any character that is not a
digit. This is identical to
[^0‐9]
.
\D
Matches a form‐feed character.
\f
Matches a line‐feed character.
\n
Matches a carriage return character.
\r
/\s/
matches the space in
“
not now
.”
Matches any white space character,
including space, tab, line‐feed, etc.
This is identical to
[ \f\n\r\t\v]
.
\s
/\S/
matches
a
in “
a
.”
Matches any character other than
a white space character. This is
identical to
[^ \f\n\r\t\v]
.
\S
continues