How do i match "00:04" and "4+21:08" which is ("days+hrs:mins" and "hrs:mins") in a file. I would like to combine regex patterns so I can calculate running time.

This is what i got for regex but does not match "00:04" --> (\d\d)(\:)(\d\d)

if($string = ~ m/(\d)(\+)(\d\d)(\:)(\d\d)/)
{
  #code goes here
}

Recommended Answers

All 2 Replies

$string="4+21:00";

if ($string=~ m{(\d\+)?(\d\d)(\:)(\d\d)}){
print "\nMatched : $&";
}
else {
print "\nNot Matched";
}

the "?". thats the key. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.