in reply to Re: Re: positive integer identification (regular expression question)
in thread positive integer identification (regular expression question)

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

Replies are listed 'Best First'.
Re: Re^3: positive integer identification (regular expression question)
by CountZero (Bishop) on Feb 08, 2003 at 19:40 UTC

    You're quite right about the use of ?. I forgot that it stands for {0,1}.

    What would you say about /^[-+]?\d+\.?0*$/? No capturing or clustering parentheses necessary and it will accept an (optional) plus-sign as well.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law