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


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

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.