Title: Match Times
Slug: match_times
Summary: Match Times
Date: 2016-05-01 12:00
Category: Regex
Tags: Basics
Authors: Chris Albon
Based on: StackOverflow
In [24]:
# Load regex package
import re
In [25]:
# Create a variable containing a text string
text = 'Chris: 12:34am. Steve: 16:30'
In [27]:
# Find any text that fits the regex
re.findall(r'([0-1]\d:[0-5]\d)\s*(?:AM|PM)?', text)
Out[27]: