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])';
In reply to Re: A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]
by Riales
in thread A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]
by aware74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |