Forum: Ruby Date-building regexes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A90204c955db033cd975f7bb0ec9600b?d=identicon&s=25 Ashley Moran (Guest)
on 2006-04-26 11:19
(Received via mailing list)
Hi

Does anyone know of a regular expression for *building* a date?  That is
one
that will match "3", "30", "30/", "30/0" (etc), but not "30/099" or
(ideally) "30/02"?  I've had a quick look into it and it seems pretty
complex, and I figured someone must have solved the problem before.

Thanks
Ashley
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2006-04-26 11:41
(Received via mailing list)
2006/4/26, Ashley Moran <work@ashleymoran.me.uk>:
> Hi
>
> Does anyone know of a regular expression for *building* a date?  That is one
> that will match "3", "30", "30/", "30/0" (etc), but not "30/099" or
> (ideally) "30/02"?  I've had a quick look into it and it seems pretty
> complex, and I figured someone must have solved the problem before.

Not 100% sure but it might be more efficient to just implement the
automata that matches the pattern and feed events (i.e. chars) to it
while the user enters them.  Otherwise your regexp will grow pretty
complex as you have to provide options / alternatives for every
possible path the pattern can take. HTH

Kind regards

robert
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-26 16:35
(Received via mailing list)
On Wed, 26 Apr 2006, Ashley Moran wrote:

> Hi
>
> Does anyone know of a regular expression for *building* a date?  That is one
> that will match "3", "30", "30/", "30/0" (etc), but not "30/099" or
> (ideally) "30/02"?  I've had a quick look into it and it seems pretty
> complex, and I figured someone must have solved the problem before.
>
> Thanks
> Ashley

not regexes - but this may solve your problem.

http://runt.rubyforge.org/

-a
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-04-26 22:19
(Received via mailing list)
Ashley Moran wrote:
>
I'm not sure exactly what you mean by 'building' a date, but have you
looked at Date::parse? Does that do what you want?

http://ruby-doc.org/core/classes/Date.html#M001576

-Justin
B81659fa35f4cf2da37bca8664ffc7d0?d=identicon&s=25 Craig Kim (Guest)
on 2006-04-29 01:30
(Received via mailing list)
Here's what you can do:

mydate = '2/4/2006'
match = /\b(0?[1-9]|1[012])[- \/.](0?[1-9]|[12][0-9]|3[01])[-
\/.](19|20)?[0-9]{2}\b/.match(mydate)


On Wed, 26 Apr 2006, Robert Klemme wrote:

> while the user enters them.  Otherwise your regexp will grow pretty
>
>
>
>

--Craig Kim
   Octo Performance Engineering, Inc
This topic is locked and can not be replied to.