javascript - RegEx Pattern - Time Format -


i've problem regex pattern , it's maddening me ;-)

can me, please?

my regex pattern:

/(\d+)?:?(\d+):(\d+)/ 

time-strings:

2:03, 24:35, 2:43:36 

output:

array [ "2:03", undefined, "2", "03" ]  // correct array [ "24:35", "2", "4", "35" ]       // should be: [ "24:35", undefined, "24", "35" ] array [ "2:43:36", "2", "43", "36" ]    // correct 

i believe need non-capture group surrounding optional first digits , colon:

(?:(\d+)?:)?(\d+):(\d+) 

here example returning results wanted: http://www.regexr.com/3b4m2


Comments