I know this has been asked but I am unable to fix it
For a book object with body (spanish): "quiero mas dinero" (actually quite a bit longer)
My Matcher keeps returning 0 for:
String s="mas"; // this is for testing, comes from a List<String>
int hit=0;
Pattern p=Pattern.compile(s,Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(mybooks.get(i).getBody());
m.find();
System.out.println(s+" "+m.groupCount()+" " +mybooks.get(i).getBody());
hit+=m.groupCount();
I keep getting "mas 0 quiero mas dinero" on console. Why oh why?
.groupCount()returns zero. Note that this does not return how many matches were found.int count = 0; for (; m.find(); count++);should give you what you want.Pattern.splitAsStream().count().