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

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.