I presume you're referring to regular expressions. There is a difference: there are non-greedy quantifiers such as "??", "*?" and "+?", in contrast to greedy quantifiers like "?", "*" and "+". According to K&B, only greedy quantifiers are examined in SCJP 5.
Thanks for the URLs. Also iam getting bit scared as my exam is within 2 weeks away and i have read some basics ..Anyways i will give it a go.I dont have much time.I have allocated only 1 month for the exam.So fingers crossed.I hope i pass the exam;-);-)
Cheers Prashanth
prashanth kumar
Ranch Hand
Joined: Mar 22, 2004
Posts: 162
posted
0
Hello, I have again got this confusion.. How can i ever find out when is a quantifier becomes greedy ex: 1)proj([^,])* --> is a quantifier
2).*xx --> is a greedy quantifier
can anyone advice?
Thanks
Marcus Green
arch rival
Rancher
Joined: Sep 14, 1999
Posts: 2813
posted
0
Did you write the text at that link yourself Wise?
So according to it,given the following text "proj3.txt,proj1sched.pdf,proj1,proj2,proj1.java"
and pattern
proj1([^,])*
why doesnt it match the whole text..It acts as a reluctant and matches
proj1sched.pdf proj1 proj1.java
Just because the regex doesn't match the "whole text" doesn't make the qualifier "reluctant". In this case, the "greedy" qualifier still has to obey what is being qualified ([^,]) and can't match anything with commas.
If you change the qualifier in the pattern to reluctant:
proj1([^,])*?
You will see that each find() will try to match as little as possible. And the matches are...
proj1 proj1 proj1
Hope this helps, Henry
Marcus Green
arch rival
Rancher
Joined: Sep 14, 1999
Posts: 2813
posted
0
Did you write the text at that link yourself Wise?
Ernest Friedman-Hill
author and iconoclast
Marshal