in reply to Parsing Timestamp with extra spaces

If you don't want to use a tested module and are willing to roll your own (you may feel you need something very specific), maybe something like:

c:\@Work\Perl\monks>perl -wMstrict -le "my $timestamp = 'Tue May 9, 2020 - 1:18:19'; ;; my $rx_wday = qr{ (?i) (?: mon | tue | wed | thu | fri | sat | sun) } +xms; my $rx_mon = qr{ [[:alpha:]]+ }xms; my $rx_day = qr{ (?: 3 [01] | [012]? \d) }xms; my $rx_year = qr{ \d{4} }xms; my $rx_24hr = qr{ (?: 2 [0123] | [01]? \d) }xms; my $rx_min = qr{ (?: [0-5]? \d) }xms; my $rx_sec = $rx_min; ;; my $got_date_time = my ($wday, $mon, $day, $year, $hr, $min, $sec) = $timestamp =~ m{ \b ($rx_wday) \s+ ($rx_mon) \s+ ($rx_day) , \s+ ($rx_year) \s+ - \s+ ($rx_24hr) : ($rx_min) : ($rx_sec) \b }xms; ;; die qq{bad timestamp '$timestamp'} unless $got_date_time; ;; print qq{'$wday' '$mon' '$day' '$year' '$hr' '$min' '$sec'}; " 'Tue' 'May' '9' '2020' '1' '18' '19'
Of course, if you choose this path, a thorough test suite is highly recommended; see Test::More.

If you roll your own, you can get highly specific. E.g., for month names (untested):
    qr{ [Jj]an (?: uary)? | ... | [Ss]ep (?: t (?: ember)? )? | ... }xms
One could do something similar for day names.

Update 1: The  (?: ...) non-capturing group in the definition of  $rx_wday is not needed (but does no harm). What was I thinking?

Update 2: The  $rx_day regex
    qr{ (?: 3 [01] | [012]? \d)  }xms
allows invalid day/date numbers of 0 and 00. The regex
    qr{ 3 [01] | [12] \d | 0? [1-9] }xms
fixes this. Note, however, that the day/date number is not reconciled with the month, so a date of, e.g., Feb 31 will be accepted! (The previous definition of  $rx_day had and some other regex definitions still have unneeded, harmless  (?: ...) non-capturing groups as mentioned in Update 1. The reason for these groups is that I originally wrote all the date component regexes with  \b boundary assertions at the start and end. This necessitated grouping any alternations together due to regex operator precedence issues. I then decided to remove the  \b boundary assertions because the other separator sequences in the main pattern were enough boundary control, but forgot to remove the now-redundant groupings. Encompassing  \b assertions are used in the  m// main match.)


Give a man a fish:  <%-{-{-{-<