You must write a regular expression that would satisfy the following formats, if possible:

HH:MM:SS H:MM:SS MM:SS M:SS 
  • 3
    Of course available. Necessary - write. What exactly did you try to do and what did not work out for you? - Mike

1 answer 1

https://regex101.com/r/yI8aS6/1
Expression

 \b(?=\d+:\d)((?:(?:2[0-3]|[0-1]?[0-9]):(?=\d\d))?(?:[0-5]?[0-9]:)?[0-5][0-9])\b 

Free entry:

 \b # граница слова (?=\d+:\d) # требование, чтобы справа были цифры, двоеточие, снова цифра ((?:(?:2[0-3]|[0-1]?[0-9]):(?=\d\d))? # HH то есть 0-23, двоеточие и две цифры справа обязательно, чтобы не было HH:M:SS (?:[0-5]?[0-9]:)? # MM то есть 0-59, двоеточие [0-5][0-9])\b # SS то есть 0-59 и граница слова 

https://regex101.com/r/yI8aS6/2
The second version of the expression

 (?:[^\d:]|^)\b(?=\d+:\d)((?:(?:2[0-3]|[0-1]?[0-9]):(?=\d\d))?(?:[0-5]?[0-9]:)?[0-5][0-9])\b 

Add

 (?:[^\d:]|^) # не цифра, двоеточие или начало строки 

It does not partially coincide 61:34:23 .
In this expression, the result in the first group, a complete match may contain an extra literal.

  • Fine! Thank you very much! - Alex Nevajniy