var regStr = "Java is very good"; Matcher m = Pattern.compile("\w+").matcher(regStr); while(m.find()){ System.out.println(m.group() + " start:" + m.start() + ",end:" + m.end()); }
output:
Java start:0,end:4 is start:5,end:7 very start:8,end:12 good start:13,end:17