v Match Times - Regex

Match Times

Based on: StackOverflow

Preliminaries

# Load regex package
import re

Create some text

# Create a variable containing a text string
text = 'Chris: 12:34am. Steve: 16:30'

Apply regex

# Find any text that fits the regex
re.findall(r'([0-1]\d:[0-5]\d)\s*(?:AM|PM)?', text)
['12:34', '16:30']