How can I find all substrings that match a regex in Java? (Similar to Regex.Matches in .Net)
+4
A:
Create a Matcher and use find()
to position it on the next match.
Aaron Digulla
2009-08-12 15:35:11
:( :( :( :( :( :(
ripper234
2009-08-12 15:44:35
+5
A:
Here is the code:
int countMatches(Pattern pattern, String str)
{
int matches = 0;
Matcher matcher = pattern.matcher(str);
while (matcher.find())
matches++;
return matches;
}
ripper234
2009-08-12 15:59:58