Regular Expressions 101

Community Patterns

Timestamp recognizer, extracts hours minutes seconds

0

Regular Expression
Python

r"
(?<![:0-9])(?P<hours>0?[0-9]|1[0-9]|2[0-3]):(?P<minutes>60|[0-5][0-9])(?::)?(?P<seconds>60|[0-5][0-9])?(?![:0-9]+\b)
"

Description

Recognizes time-of-day timestamps

  • Time range is from 0:00:00 through 23:59:59
  • Seconds are optional
  • Named match components for hours, minutes, seconds
Submitted by Paul Reiber - 8 years ago