Get Indexes
You can obtain the index within the input sequence of the current match by calling start( ) method. The index one past the end of the current match is obtained by calling end( ) method.
Program
Program Source
import java.util.regex.Pattern; import java.util.regex.Matcher; public class Javaapp { public static void main(String[] args) { Pattern pat = Pattern.compile("Java"); Matcher mat = pat.matcher("Java6Java7Java8"); int i = 0; while(mat.find()) { i++; System.out.println(i+"th subsequence intex : "+mat.start()+"-"+mat.end()); } } }