can somone explain to me about the regular expressions and how greedy, reluctant, possesive quantifiers work, also the new locale class and the printf() method. I have read the MZ's SCJP Tiger Notes but I am still not clear. --------------------
Originally posted by Ravith Botejue: can somone explain to me about the regular expressions and how greedy, reluctant, possesive quantifiers work, also the new locale class and the printf() method. I have read the MZ's SCJP Tiger Notes but I am still not clear. RB
To be blunt, regular expressions are *very* complex. And in many ways, can be regarded as a complete language on its own.
Unfortunately, the Java Documentations assumes that you already know regular expressions, and just summarized the topic.
The best documentation that I have seen on Regular Expressions are actually part of the perl documentation. Search the perl.com website for the regular expression documentation. And while you are at it, learning perl may not be a bad idea either...
Fortunately, the objectives only mention greedy quantifiers, which are the default behavior.
The quantifiers you need to know about are:
* ... matches zero or more occurrences of the preceding pattern. + ... matches 1 or more occurrences of the preceding pattern. ? ... matches zero or 1 occurrence.
A greedy quantifier will match the longest possible sequence of characters. A reluctant or possessive quantifier might not match the longest possible sequence, depending on some really intricate principles that fortunately aren't required knowledge for the SCJP exam.
Makes me wonder what future enhancements we might see? How about an obsessive-compulsive quantifier, which consumes all characters even if it's not appropriate. Or a manic-depressive quantifier, which cycles between greedy and reluctant behavior.
Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".