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 first 'Bond'
matcher.find();
int startIndex = matcher.start();
System.out.println(candidateString);
System.out.println(matchHelper[0] + startIndex);
}
}
|