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 mistake of calling matcher.goup() without a prior call to matcher.find(), matcher.matches(), or matcher.lookingAt()

This annoying mistake is found in many programs. As the heading says, these are cases where programmers call any of the group() methods without a prior call to the find, matches, or lookingAt methods. A matcher is created using the pattern.matcher(String) method call, but we need to invoke one of these three methods to perform a match operation.

If we call matcher.group() without calling one of these three methods, then the code will throw a java.lang.IllegalStateException exception, as the following code is doing:

 package example.regex; import java.util.regex.*; public class MissingMethodCall { public static void main(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