How to extract only time elements from a hash?
More general approach:
hash = {"19th Apr, 2013" => :a, "20th Apr, 2013" => :b,"Tomorrow" => :c,"5:00 PM" => :d,"09:25 PM" => :e , "23:23" => :f}
hash.delete_if{|k,v| k !~ /\d{1,2}:\d\d/}
=> {"5:00 PM"=>:d, "09:25 PM"=>:e, "23:23" => :f}
NOTE:
- it also allows 24 hour time format
- it also handles the case when the hour is only one digit
if you do not want to handle the 24-hour format, use:
hash = {"19th Apr, 2013" => :a, "20th Apr, 2013" => :b,"Tomorrow" => :c,"5:00 PM" => :d,"09:25 PM" => :e , "23:23" => :f}
hash.delete_if{|k,v| k !~ /\d{1,2}:\d\d/ [AaPp][Mm]} # am AM pm PM
=> {"5:00 PM"=>:d, "09:25 PM"=>:e}