this question has answer here:
- java regex match count 2 answers
i tried regex tester , works. why can't work java. hoping search neither..........nor
i want count how many neither
somethingnor
in string : "neither u or me human"
.
i have tried :
occurrence += sentence.split( "(?i)\\wneither.+nor\\w" ).length - 1;
but not working because output system.out.print(occurrence)
result 0
.
i thought \\w
stands non-word character while .+
means character(s).
how can occurrence
result of 1
?
you can count occurrences this:
pattern pattern = pattern.compile("(neither|nor)", pattern.case_insensitive); matcher matcher = pattern.matcher("neither u or me human"); int count = 0; while (matcher.find()) count++; system.out.println(count);
Comments
Post a Comment