jakarta-oro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Masters" <jo...@eepulse.com>
Subject Number of occurrences of a regular expression
Date Mon, 22 Jan 2001 18:57:20 GMT
I need to know the number of times an expression occurrs in a string.  The following code produces
this information for me:

pattern = compiler.compile("({\\d+})");
int matches = 0;
  
while(matcher.contains(input, pattern)) 
{
   matches++;
}

Is there a better way to do this?  I was hoping to be able to call

   matcher.contains(input, pattern);
   matcher.getMatch().groups();

but  that doesn't return what I need ( it always appears to return one more, I guess ).

I dislike the loop, and it seems like this count should be more easily available.

Any suggestions would be helpful.

John




Mime
View raw message