Regular expression languages also have character classes. : Introduction « Regular Expressions « Java Tutorial






Character classes specify a list of possible characters that can match any single character in the string you want to match.

  1. Using the expression [^012], any single digit except for 0, 1, and 2 is matched.
  2. You can specify character ranges using the dash.
  3. The character class [a–z] matches any single lowercase letter.
  4. [^a–z] matches any character except a lowercase letter.
  5. [0–9] to match a single digit.
  6. [0–3] to match a 0, 1, 2, or 3.
  7. [a–zA–Z] to match any single letter.
Character Class Meta-CharacterMatches
.Any single character
\dA digit [0–9]
\DA nondigit [^0–9]
\sA whitespace character [ \t\n\x0B\f\r]
\SA nonwhitespace character [^\s]
\wA word character [a–zA–Z_0–9]
\WA nonword character [^\w]










8.1.Introduction
8.1.1.Meta-characters predefined to match specific characters.
8.1.2.Meta-characters to match against certain string boundaries.
8.1.3.Regular expression languages also have character classes.
8.1.4.POSIX character classes and Java character classes
8.1.5.Java Character Class
8.1.6.Match a particular character a specified number of times.
8.1.7.Read regular expression from console
8.1.8.Regex Test Harness
8.1.9.Match Java source file and file and class name
8.1.10.Finding all words that start with an 'a'
8.1.11.Simple validation using the Pattern and Matcher objects
8.1.12.A possessive qualifier
8.1.13.Find the starting point of the second 'Bond'
8.1.14.A negative look ahead
8.1.15.A negative behind ahead
8.1.16.A positive look ahead
8.1.17.Pattern helper
8.1.18.Escapes characters that have special meaning to regular expressions