The Pattern class

The Pattern class represents the compiled form of a string regular expression. So far, we have provided all the regular expressions as strings. Each String regular expression must be compiled into an instance of the Pattern class before the Java regex engine can execute it. An instance of the Pattern class is used to create a Matcher object to match input text against the regular expression.

Let's list down the important and useful methods from the Pattern class first:

Method Signature

Description

Static Pattern compile(String regex)

Compiles the given String regular expression into a Pattern instance.

Static Pattern compile(String regex, int flags)

Compiles the given String regular expression into a Pattern ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.