Hi Ranchers,
Please find the following code and let me know how exactly start and group work in this case and the output shows even 6.
code:
--------------------------------------------------------------------------------
import java.util.regex.*;
class Regex2 {
public static void main(
String[] args) {
Pattern p = Pattern.compile("\\d*");
Matcher m = p.matcher("ab89ef");
boolean b = false;
while(b = m.find()) {
System.out.print(m.start() + m.group());
}
}
}
--------------------------------------------------------------------------------
In this code acording to me the index will start from
0-a
1-b
2-8
3-9
4-e
5-f
since we have * it means all are true for matching, but the output is
01289456. How is 6 in the output and how does the regex engine work to produce this output. Kindly explain the same.
Thanks and best Regards,
Pradeep
[ November 07, 2008: Message edited by: Pradeep Kumar ]