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

Introduction to the Java String API for regular expressions' evaluation

The Java String API provides some useful methods to evaluate regular expressions against a text represented by the String object. Let's list those methods from the String class:

Method Signature

Purpose

boolean matches(String regex)

Matches the given regular expression against the string that the method is invoked on and returns true/false, indicating whether the match is successful (true) or not (false).

String replaceAll(String regex, String replacement)

Replaces each substring of the subject string that matches the given regular expression with the replacement string and returns the new string with the replaced content.

String replaceFirst(String ...

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