O'Reilly logo

Java 9 Regular Expressions by Anubhava Srivastava

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required