If you prefer regex, this is a regex solution:
String example = "Hello my is Joeseph. It is very nice to meet you. isWhat a wonderful day it is!"; Matcher m = Pattern.compile("\\bis\\b").matcher(example); int matches = 0; while(m.find()) matches++; System.out.println(matches);
In this case, the "is" in "isWhat" is ignored due to the \ b border matching in the pattern
Tropid
source share