I would just modify any single digits before parsing.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @dateStrs = ( q{Fri May 8, 2020 - 11:12:13}, q{Fri May 15, 2020 - 14:08:17}, q{Sat May 16, 2020 - 7:31:22}, q{Mon Jun 1, 2020 - 6:24:18}, ); s{(?<=\D)(\d)(?=\D)}{ sprintf q{%02d}, $1 }eg for @dateStrs; say for @dateStrs;' Fri May 08, 2020 - 11:12:13 Fri May 15, 2020 - 14:08:17 Sat May 16, 2020 - 07:31:22 Mon Jun 01, 2020 - 06:24:18

Perhaps the problem is more complex than stated in the OP but this seems to work.

Update: A version that copes properly with extra spaces, the first version didn't.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' my @dateStrs = ( q{Fri May 8, 2020 - 11:12:13}, q{Fri May 15, 2020 - 14:08:17}, q{Sat May 16, 2020 - 7:31:22}, q{Mon Jun 1, 2020 - 6:24:18}, q{Fri May 8, 2020 - 11:12:13}, q{Fri May 15, 2020 - 14:08:17}, q{Sat May 16, 2020 - 7:31:22}, q{Mon Jun 1, 2020 - 6:24:18}, ); s{(\s+\d)(?=\D)}{ sprintf q{ %02d}, $1 }xeg for @dateStrs; say for @dateStrs;' Fri May 08, 2020 - 11:12:13 Fri May 15, 2020 - 14:08:17 Sat May 16, 2020 - 07:31:22 Mon Jun 01, 2020 - 06:24:18 Fri May 08, 2020 - 11:12:13 Fri May 15, 2020 - 14:08:17 Sat May 16, 2020 - 07:31:22 Mon Jun 01, 2020 - 06:24:18

Cheers,

JohnGG


In reply to Re: Parsing Timestamp with extra spaces by johngg
in thread Parsing Timestamp with extra spaces by htmanning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.