import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainClass {
public static void 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 second 'Bond'
matcher.find();
int nextIndex = matcher.start();
System.out.println(candidateString);
System.out.println(matchHelper[1] + nextIndex);
}
}
|