David Newton wrote:Did you read the link Rob provided? Note that in your original example you already *have* a quantified, the asterisk *... I'm not sure why you'd use a ? Or + after it
Umm, those
are addressed in the link Rob provided. Plain * is a greedy quantifier, 0 or more times. *? is a reluctant quantifier, zero or more times. *+ is a possessive quantifier, zero or more times.
What's missing from the JavaDoc, of course, is any decent explanation of the differences between greedy, reluctant, and possessive. Instead we are referred to
Mastering Regular Expressions, 3nd Edition, Jeffrey E. F. Friedl. A great book, but not readily available online, at least not for free. The truth is, the JavaDoc kind of sucks here. Back when I learned JDK 1.4 regex, there was no real alternative online, you just had to buy the book (2nd edition then). Now, however, there are decent online explanations available.
Chandana, I recommend looking that the Java tutorial,
Differences Among Greedy, Reluctant, and Possessive Quantifiers
David Newton wrote:what happened when you tried it?
Always good advice, especially for code where one asks "what is the result?" Chandana,
you should have been able to discover the result pretty easily here by simply running the code. A better question is
why do you get the results you do. That's answered, I hope, in the tutorial link I gave.