The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Feedback Form

Trail: Bonus

Lesson: Regular Expressions

by Scott A. Hommel


Note: This lesson covers an API introduced in the latest release of the JavaTM 2 Platform Standard Edition, version 1.4. Visit the J2SE 1.4 download page.
This lesson explains how to use the java.util.regex (in the API reference documentation) API for pattern matching with regular expressions. This lesson does not assume the that you have any previous experience with regular expressions. Although the syntax of regular expressions that this package accepts is similar to Perl, knowledge of the Perl programming language is not a prerequisite. This lesson starts with the basics, and gradually builds to cover more advanced techniques.

Note: We recommend that you open java.util.regex (in the API reference documentation) API specification in a separate browser window. You may want to consult it throughout this lesson.
Introduction (in the Bonus trail)
Gives a general overview of regular expressions. It also introduces the core classes that comprise the regex API.

Test Harness (in the Bonus trail)
Defines reusable code for testing and explores pattern matching with regular expressions.

String Literals (in the Bonus trail)
Introduces basic pattern matching, metacharacters, and quoting.

Character Classes (in the Bonus trail)
Describes simple character classes, negation, ranges, unions, intersections, and subtraction.

Predefined Character Classes (in the Bonus trail)
Describes the basic predefined character classes for whitespace, word, and digit characters.

Quantifiers (in the Bonus trail)
Explains greedy, reluctant, and possessive quantifiers for matching a specified expression x number of times.

Capturing Groups (in the Bonus trail)
Explains how to create groups so that you can treat multiple characters as a single unit.

Boundary Matchers (in the Bonus trail)
Describes line, word, and input boundaries.

Methods of the Pattern Class (in the Bonus trail)
Examines other useful methods of the Pattern class, and explores advanced features such as compiling with flags and using embedded flag expressions.

Methods of the Matcher Class (in the Bonus trail)
Describes the commonly-used methods of the Matcher class.

Methods of the PatternSyntaxException Class (in the Bonus trail)
Describes how to examine a PatternSyntaxException.

Additional Resources (in the Bonus trail)
To read more about regular expressions, consult this section for additional resources.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Feedback Form

Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.