Boost logo

Boost Users :

From: Eric Niebler (eric_at_[hidden])
Date: 2006-04-12 15:09:33


Lynn Allan wrote:
> Eric Niebler wrote:
>
>>Lynn Allan wrote:
>>
>>>But, in example 2, seems like "year" should be repeat<1,4>, but:
>>>year= repeat<1,2> works:
>>>
>>>cregex date = (month= repeat<1,2>(_d)) // find the month ...
>>>
>>>>>(delim= (set= '/','-')) // followed by a delimiter ...
>>>>>(day= repeat<1,2>(_d)) >> delim // and a day followed by the same
>>>>>delimiter ...
>>>>>(year= repeat<1,2>(_d >> _d)); // and the year.
>>>
>>>actually, repeat<1,3> works for month, day, and year. Am I mixed up
>>>on what "repeat" means?
>>
>>
>>repeat<n,m>(X) means to match X between n and m times, inclusive. So
>>matching a month a day, you want repeat<1,2>(_d) to match 1 or 2
>>digit
>>characters, and to match a year, you want repeat<1,2>(_d >> _d) to
>>match two digits or four digits. Three digits isn't a common
>>representation of a year.
>
>
> Ok .... and thanks for your patient assistance.
>
> I think I see why repeat<1,2> works for yyyy, but AFAICT, the
> repeat<1,3> "worked" for day dd and month mm, which seems off. I
> changed the sample code "just to see what would happen" and was
> scratch-my-head-surprised to get the same results from repeat<1,2> as
> for repeat<1,3> .... days and months were "captured".

repeat<1,3>(_d) will match one digit, or two digits, or three digits.
So, yes, it will match days (which are one or two digits) or months
(which are one or two digits). However, it is overly permissive, because
it will also match three digits, which is not a valid day or month.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net