Ruby: How to use regex to see if string is in date format with dashes? -
i want see if string passed in yyyy-mm-dd format.
string = "2013-03-02" string[/\d{4}-\d{2}-\d{4}/] #why return nil?
i want check there 4 digits, followed dash, followed 2 digits, followed dash, followed 2 digits.
\d{4}-\d{2}-\d{4}
should \d{4}-\d{2}-\d{2}
per wish.
(arup~>~)$ pry --simple-prompt >> string = "2013-03-02" => "2013-03-02" >> string[/\d{4}-\d{2}-\d{2}/] => "2013-03-02" >> string = "2013-03-2" => "2013-03-2" >> string[/\d{4}-\d{2}-\d{2}/] => nil
Comments
Post a Comment