Duration (HH:MM:SS) Regex Pattern
Validates elapsed duration strings in HH:MM:SS format with any hour count, minutes 00-59, and seconds 00-59. Use for video length, stopwatch timers, time tracking, and log duration fields.
Reviewed May 31, 2026. Privacy model: tool input is processed in your browser and is not uploaded to BytePane servers.
Live Regex Tester
Pattern Breakdown
Code Examples
JavaScript
const regex = /^\d+:[0-5]\d:[0-5]\d$/; const test = "01:30:45"; console.log(regex.test(test)); // true // Extract matches const matches = test.match(regex); console.log(matches);
Python
import re pattern = r'^\d+:[0-5]\d:[0-5]\d$' test = "01:30:45" match = re.search(pattern, test) print(match) # Found!
Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^\d+:[0-5]\d:[0-5]\d$`)
fmt.Println(re.MatchString("01:30:45")) // true
}Common Use Cases
Match Examples
| Input | Result |
|---|---|
| 01:30:45 | Match |
| 1:60:00 | No Match |
Duration regex variants for HH:MM:SS, MM:SS, optional hours, and ISO 8601
The base pattern validates elapsed duration strings such as 01:30:45 or 125:00:00. Use a narrower variant when a product needs fixed two-digit hours, media-player MM:SS input, optional hours, millisecond precision, or ISO 8601 duration strings.
| Variant | Pattern | Use it when |
|---|---|---|
| Strict two-digit HH:MM:SS | ^(?:[0-9]{2}):[0-5][0-9]:[0-5][0-9]$ | Use when the UI always stores two hour digits, such as 01:30:45, and should reject 1:30:45. |
| Optional hours, MM:SS or HH:MM:SS | ^(?:(?:\d+):)?[0-5]\d:[0-5]\d$ | Use for media players and timers that accept 03:45 for short clips and 1:03:45 for longer durations. |
| HH:MM:SS with milliseconds | ^\d+:[0-5]\d:[0-5]\d(?:\.\d{1,3})$ | Use for logs, sports timing, subtitle tools, and telemetry where 01:30:45.250 should be valid. |
| ISO 8601 duration subset | ^P(?=\d|T\d)(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$ | Use when APIs exchange durations as P1DT2H30M, PT45M, or PT30S instead of colon-separated timers. |
Edge cases to test
01:30:45MatchThe base pattern accepts any hour count followed by valid minutes and seconds.
1:30:45MatchSingle-digit hours are valid in the base pattern. Use the strict two-digit variant to reject them.
03:45No match in base patternThe base pattern requires hours. Use the optional-hours variant for MM:SS media duration input.
1:60:00No matchMinutes must be 00-59.
1:30:60No matchSeconds must be 00-59.
PT1H30MNo match in base patternThat is ISO 8601 duration syntax, not HH:MM:SS.
About the Duration (HH:MM:SS) Regex
Validates elapsed duration strings in HH:MM:SS format with any hour count, minutes 00-59, and seconds 00-59. Use for video length, stopwatch timers, time tracking, and log duration fields.
Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The duration (hh:mm:ss) pattern is classified as <strong>beginner</strong> difficulty in the <strong>date & time</strong> category. It works in all major programming languages.
When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.
More Date & Time Patterns
Need More Regex Patterns?
Browse our complete library of 100+ regex patterns with interactive testers.
Frequently Asked Questions
What is the Duration (HH:MM:SS) regex pattern?
Validates elapsed duration strings in HH:MM:SS format with any hour count, minutes 00-59, and seconds 00-59. Use for video length, stopwatch timers, time tracking, and log duration fields.
How do I use the Duration (HH:MM:SS) regex?
Use the pattern /^\d+:[0-5]\d:[0-5]\d$/ in your code. In JavaScript: new RegExp('^\d+:[0-5]\d:[0-5]\d$', ''). Test it above with your own input.
What does this Duration (HH:MM:SS) regex match?
This pattern matches: "01:30:45". It does NOT match: "1:60:00". Video duration, timer display, time tracking.
Is the Duration (HH:MM:SS) regex beginner-friendly?
This pattern is rated Beginner. It uses basic regex syntax and is easy to understand.
What languages support the Duration (HH:MM:SS) regex?
This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.
Can I modify the Duration (HH:MM:SS) regex for my use case?
Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.
Related Tools
Date (YYYY-MM-DD) Regex
Intermediate Date & Time pattern
Date (MM/DD/YYYY) Regex
Intermediate Date & Time pattern
Date (DD/MM/YYYY) Regex
Intermediate Date & Time pattern
Time (24-hour) Regex
Beginner Date & Time pattern
Time (12-hour) Regex
Beginner Date & Time pattern
ISO 8601 DateTime Regex
Advanced Date & Time pattern