Regex for Time with Milliseconds
Regex Pattern
^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{1,3}$Time in HH:MM:SS.mmm format with milliseconds
Quick Answer
The regex pattern for time with milliseconds is `^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{1,3}$`. Time in HH:MM:SS.mmm format with milliseconds. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 14:30:00.123 | ✓ Matches |
| 00:00:00.0 | ✓ Matches |
| 23:59:59.999 | ✓ Matches |
| 14:30:00 | ✗ No match |
| 24:00:00.000 | ✗ No match |
| 14:30 | ✗ No match |
Code Examples
javascript
const regex = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{1,3}$/;
const isValid = regex.test(value);python
import re
pattern = r'^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{1,3}$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{1,3}$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{1,3}$/', $value)) {
echo "valid";
}java
String pattern = "^([01]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)\\.\\d{1,3}$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
Date YYYY-MM-DD
ISO 8601 date format
Date DD/MM/YYYY
European date format with slashes
24-Hour Time
24-hour clock time in HH:MM format
12-Hour Time with AM/PM
12-hour clock with AM/PM
Date MM/DD/YYYY
US date format with slashes (MM/DD/YYYY)
ISO 8601 Full DateTime
Full ISO 8601 datetime with timezone (YYYY-MM-DDThh:mm:ssZ)