Use a non capturing group (?:
and reference to the match group.
Use re.I
for case insensitive matching.
import re
def find_t(text):
return re.search(r'd{2}:d{2}(?:am|pm)', text, re.I).group()
You can also use re.findall()
for recursive matching.
def find_t(text):
return re.findall(r'd{2}:d{2}(?:am|pm)', text, re.I)
See demo
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…