Java Reference
In-Depth Information
Table 9-1 provides an expanded list of metacharacters available for Java regexs.
Table 9-1. Regex metacharacters
Metacharacter
Meaning
Notes
Optional character—zero or one instance
?
Zero or more of preceding character
*
One or more of preceding character
+
Between M and N instances of preceding character
{M,N}
A digit
\d
A nondigit character
\D
A word character
Digits, letters, and _
\w
A nonword character
\W
A whitespace character
\s
A nonwhitespace character
\S
Newline character
\n
Tab character
\t
Any single character
Does not include newline in Java
.
Any character contained with the brackets
Called a character class
[ ]
Any character not contained with the brackets
Called a negated character class
[^ ]
Build up a group of pattern elements
Called a group (or capturing group)
( )
| Deine alternative possbilities
Implements logical OR
Start of string
^
End of string
$
m
m
n
s
There are a few more, but this is the basic list, and from this, we can construct more
complex expressions for matching such as the examples given earlier in this section:
a
 
Search WWH ::




Custom Search