Tutorial: Regular Expressions

This lesson explains how to use the java.util.regex API for pattern matching with regular expressions. Although the syntax accepted by this package is similar to the programming language, knowledge of Perl is not a prerequisite. This lesson starts with the basics, and gradually builds to cover more advanced techniques.

Provides a general overview of regular expressions. It also introduces the core classes that comprise this API.
Defines a simple application for testing pattern matching with regular expressions.
Introduces basic pattern matching, metacharacters, and quoting.
Describes simple character classes, negation, ranges, unions, intersections, and subtraction.
Describes the basic predefined character classes for whitespace, word, and digit characters.
Explains greedy, reluctant, and possessive quantifiers for matching a specified expression x number of times.
Explains how to treat multiple characters as a single unit.
Describes line, word, and input boundaries.
Examines other useful methods of the Pattern class, and explores advanced features such as compiling with flags and using embedded flag expressions.
Describes the commonly-used methods of the Matcher class.
Describes how to examine a PatternSyntaxException.
To read more about regular expressions, consult this section for additional resources.