[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Key-singing coordination page updated



Domenico Andreoli wrote:
> there is any regular expression that "safely" finds a date in a string?

Perl's Date::Manip does a good job:

joey@kite:~>perl -le 'use Date::Manip; while (<>) { chomp ; \
	print "> ".UnixDate(ParseDate($_), "%Y-%m-%d") }'
Thu Dec  7 19:05:30 PST 2000
> 2000-12-07
last day of december
> 2000-12-31
december 25th, 2021
> 2021-12-25
today
> 2000-12-07
yesterday
> 2000-12-06
15 days ago
> 2000-11-22
in 15 days
> 2000-12-22
in 2 months
> 2001-02-07
in 12 hours
> 2000-12-08
4/11/76
> 1976-04-11
1976-04-11
> 1976-04-11
4/11/76
> 1976-04-11

Unfortunatly, it does not handle the format "4-11-76", of course that
format is ambiguous anyway. Data::Parse can, though it misses some of
the forms above:

joey@kite:~>perl -le 'use Date::Parse; while (<>) { \
	print "> ".localtime(str2time($_)) }'    
4-11-76
> Sun Apr 11 00:00:00 1976
today
> Wed Dec 31 16:00:00 1969

:-)

-- 
see shy jo



Reply to: