3

what is the regular expression for HH:MM:SS

HH is hours , but not limited for day or clock it just can be any number from 0 to any integer

MM is minutes maximum is 59 and begin from 00

SS is Seconds maximum is 59 and begin from 00

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Alsemany
  • 445
  • 1
  • 5
  • 13

1 Answers1

7
([0-9]+):([0-5][0-9]):([0-5][0-9])

if the maximum is 59 (sensible). If you want 60 to also be possible,

([0-9]+):([0-5][0-9]|60):([0-5][0-9]|60)

EDIT: If you want the leading zero to be optional, the one in the comment works. This one is better tho:

([0-9]+):([0-5]?[0-9]):([0-5]?[0-9])
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Yeah I was wrong the maximum is 59 , I will try your regex, Thank you – Alsemany Oct 31 '13 at 01:04
  • this work good, I just changed it to `([0-9]+):([0-9]+|59):([0-9]+|59)` to match 0:0:0 times , – Alsemany Oct 31 '13 at 01:25
  • 1
    @Alsemany first off you said in your question you wanted it to be `00`. 2nd, your change will not give you what you expect. It will also match for `99:99:99` – CrayonViolent Oct 31 '13 at 02:12
  • 1
    what you really want then is `([0-9]+):([0-9]|[1-5][0-9]):([0-9]|[1-5][0-9])` – CrayonViolent Oct 31 '13 at 02:13
  • @Crayon Violent yeah , I don't know good about regex, I understand now that (|) mean (or) Thanks for help – Alsemany Oct 31 '13 at 02:23
  • after some search for regex and your notice I make this `(?:([0-9]+):|)([0-9]|[1-5][0-9]):([0-9]|[1-5][0-9])` to find the 59:59 and 111:59:59 times from the text and it work fine , please tell me if there's something wrong here !! – Alsemany Oct 31 '13 at 02:26