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

Use a compiled form of regular expressions

Compile your string regex pattern using the Pattern.compile(String) method call followed by calls to the Matcher APIs instead of calling shorthand methods in string, such as matches(), replaceAll, and replaceFirst, especially when these matching or replacement methods are invoked repeatedly inside a loop. Repeated calls to String.matches() or any other regex-based method defined in the String API will compile the String regex pattern every time; this can be very time-consuming for a complex regex 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