in reply to date format string -> Reg Ex solution
I did a small date parser for very simple in Python, and it has a very simplicistic syntax. The letters Y,M and D are used to designate the numbers which should be extracted. Any other character must appear verbatim in the string, and this is validated against.
Some examples :Date( key, 'YYMMDD' ) # Date must be 6 digits Date( key, 'YY-MM-DD' ) # Date must match /\d\d-\d\d-\d\d/ Date( key, 'DD.MM.YYYY' ) # Date in german format, 4 digit year
The implementation is very simple: As all strings are of fixed length, I extract the numbers from the left and right offsets of each letter (Y,M,D). After the extraction, I replace Y,M,D by "x", and then check that the string matches the string where the numbers also have been replaced by "x".
For my purposes (parsing various lists), this has proven good enough, as I don't have to deal with weekdays etc., that is, variable text except for digits.
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
|
|---|