Hi,
I am not able to understand un-expected behaviour of find() API of Matcher class.
As per the
java documents and my understanding, find() method return TRUE if system is able to find more occurence of sequence that matches given the
pattern.
public class RejEx {
public static void main(
String[] args) {
String source = "pp";
Pattern p = Pattern.compile("p*");
Matcher m = p.matcher(source);
while(m.find())
{
System.out.println("Pattern Found :"+m.group());
}
}
}
As per the code snippet,anybody will expect that while loop should get executed only once but it gets executed 2 times. So when I run this program I get output as below :
Pattern Found : pp
Pattern Found :
I does work fine if I use "p+" pattern but if use "p*" or "p?" as pattern than I am not getting output as per my expectation.
So now I have following questions :
1. Is my understanding not correct ?
2. Is there any BUG in find() API ?
cheers,
Sunil
[ May 14, 2008: Message edited by: Sunil Dixit ]
[ May 14, 2008: Message edited by: Sunil Dixit ]
[ May 14, 2008: Message edited by: Sunil Dixit ]