Sample code
Pattern p = Pattern.compile("\\d?");
Matcher m = p.matcher("ab34ef");
boolean b = false;
while (m.find())
{
System.out.print(m.start());// + m.group());
}
Answer: 012456
But string total length is 6. So How m.start will give 6 in the output, as index starts
from 0.