import java.util.regex.Matcher; import java.util.regex.Pattern; public class Find { public static void main(String[] args) { String regex = "\\b Tim\\b"; Pattern pattern = Pattern.compile(regex); String text = "I can confirm what Tim Bueneman analyst " + "Tim Right is saying — that Amazon.com plans " + " a larger-screen model of its Tim player" ; Matcher matcher = pattern.matcher(text); int count = 0; while (matcher.find()) { count++; System.out.println("Number of times Tim is: " + count); System.out.println("Tim Start at the index: " + matcher.start()); } } }