If I do this
(\.0*)*, then the pattern
(\.0*) will match 0 or more times. Which would mean that .0 would match but so would .0.0.0 and .000.00 . These latter matches are not part of what is considered to be at the end of an integer. The
? on the other hand means whatever pattern is before me try to match it 1 or 0 times (in this instance making it optional). Unless
? is used afer a quantifier (e.g.
+, or
?, or
{min,max}). I could alternatively have used
(\.0*){0,1} in this instance.
on the other hand if I were to have ?? then it would try to match 0 or 1 time (in that order where as before (i.e, the single ? )it would try to match it 1 time and failing that it would ignore it was there, making it optional). I understand I might be unclear but I can further clarify if needed. I know this explained in the Mastering Regular Expressions book, but I have not quite yet located it in the Camel book (i will update when/if I find it)
update: As for you question though there is no reason they are capturing parens it could just as well be (?:\.0*)? so they don't have to be capturing parens but I did not figured it mattered in this case, as I am lazy I dont normally put the ?: in the parens to make them non-capturing, unless I care what goes into the $1,$2,... series of variables, that are returned by the capturing parens.
As for it location in in the Camel book (3rd edition) refer to page 142 at the paragraph starting with "Another thing you'll see are what we call quantifiers, ..."
-enlil
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.