http://www.perlmonks.org?node_id=964845


in reply to A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]

You want the ? which allows 0 or 1 occurrence of the preceding element.

my $timeRegex = '((?:[0-1][0-9]:)?[0-5][0-9]:[0-5][0-9])';
  • Comment on Re: A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]
by aware74 (Initiate) on Apr 13, 2012 at 16:08 UTC

    Thank you. This is what happens when you don't fully understand the regex that is generated for you.