import java.util.regex.Matcher;
import java.util.regex.Pattern;
publicclass MatcherStartExample {
publicstaticvoid main(String args[]) {
String candidateString = "My name is Bond. James Bond.";
String matchHelper[] = { " ^", " ^" };
Pattern p = Pattern.compile("Bond");
Matcher matcher = p.matcher(candidateString);
//Find the starting point of the first 'Bond'
matcher.find();
int startIndex = matcher.start();
System.out.println(candidateString);
System.out.println(matchHelper[0] + startIndex);
//Find the starting point of the second 'Bond'
matcher.find();
int nextIndex = matcher.start();
System.out.println(candidateString);
System.out.println(matchHelper[1] + nextIndex);
}
}