SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
but is it not true that greedy quantifier looks at the entire source string once and then reverts back from right to find the match and include the part of the source left side to the match as the final match...
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Originally posted by saipavan vallabhaneni:
thanks henry,
but in the 1st code snippet having source "ab34ef" why is the group() method returning a null(when start() returns 0)instead of "a"(since it has 0 or more digits)...group() method returns the match that has been found(which in my guess is "a" rather than null as returned by the group())
I would still stick to my words. If you use * with a dot(.), then * will become greedy. But if you put * with a pattern, then * will be reluctant.
but in the 1st code snippet having source "ab34ef" why is the group() method returning a null(when start() returns 0)instead of "a"(since it has 0 or more digits)...group() method returns the match that has been found(which in my guess is "a" rather than null as returned by the group())
SCJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
then it would match as little as possible. So it would give you empty matches at index 1,2,3,4 etc. This is what I was trying to say. I may be wrong as I said earlier also that I have not experimented on this much...
source: yyxxxyxx
regex: .*xx
source: yyxxxyxx
regex: .*?xx
Don't get me started about those stupid light bulbs. |