Hi All,
Please tell me how combination of these quantifiers works:
import java.util.regex.*;
class Regex1
{
public static void main(
String[] args)
{
Pattern p = Pattern.compile("\\d*+");
Matcher m = p.matcher("ab34ef");
while(m.find()){
System.out.println(m.start() +" "+m.group());
}
}
}
As i know that:
* -------> zero or more occurrence
+ -------> one or more occurrence
? -------> Zero or one occurrence
suppose my input string is "ab34ef" and comparing string is "\\d*","\\d+" and "\\d?" then i will get the output if i put these comparision in the above code:
for "\\d*" -------output will be 01234456
for "\\d+" -------output will be 234
for "\\d?" -------output will be 012334456
But what will be the output if i use comaprision string like "\\d*+","\\d*?".
I am not able to draw conclusion from the output ,how exactly combinations of these quantifier working.
Please help.
Also please explain me the exact difference between
greedy,
reluctant and
possessive quantifiers with some real example.
[ January 09, 2008: Message edited by: Hamraj Kulshreshtha ]
[ January 09, 2008: Message edited by: Hamraj Kulshreshtha ]