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 find() and find(int start) methods

These find methods attempt to find the next subsequence of the input sequence that matches the pattern. These methods return true only if a subsequence of the input matches this matcher's pattern. If multiple matches can be found in the text, then the find() method will find the first, and then for each subsequent call to find(), it will move to the next match.

An example code will make it clearer:

package example.regex; import java.util.regex.*; class MatcherFindExample {   public static void main (String[] args)   {     final String input = "some text <value1> anything <value2><value3>     here";     /* Part 1 */     final Pattern pattern = Pattern.compile("<([^<>]*)>");  Matcher matcher = pattern.matcher(input); ...

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