Java Reference
In-Depth Information
Table 4-19. The List of the Predefined Character Classes
Predefined
Character Classes
Meaning
. (a dot)
Any character (may or may not match line terminators)
\d
A digit. Same as [0-9]
\D
A non-digit. Same as [^0-9]
\s
A whitespace character. Same as [\t\n\x0B\f\r] . The list
includes a space, a tab, a new line, a vertical tab, a form feed,
and a carriage return characters
\S
A non-whitespace character. Same as [^\s]
\w
A word character. Same as [a-zA-Z_0-9] . The list includes
lowercase letters, uppercase letter, underscore, and
decimal digits
\W
A nonword character. Same as [^\w]
You can also specify the number of times a character in a regular expression may
match the sequence of characters. If you want to match all two digit integers, the regular
expression would be /\d\d/ , which is the same as /[0-9][0-9]/ . What would be the
regular expression to match an integer? You cannot write the regular expression to match
an integer with the knowledge you have gained so far. You need to be able to express a
pattern “one digit or more” using a regular expression. Quantifiers and their meanings
have been listed in Table 4-20 .
Table 4-20. Quantifiers and Their Meanings
Quantifiers
Meaning
*
Zero or more times
+
One or more times
?
Once or not at all
{m}
Exactly m times
{m, }
At least m times
{m, n}
At least m , but not more than n times
 
 
Search WWH ::




Custom Search