I have a string that shows how much time is left:
text = """ 9d 15h left <br />
some other text not important
12h 5m left <br />"""
pattern = "((\d+)d)?.*left <br />"
I'd like to match the number of days, or 9. However, if that's missing, I'd like to match an empty string. This is what I get
>>> re.findall(pattern,text)
[('', ''),('', '')]
But what I'm looking for is
>>> re.findall(pattern,text)
[('9d', '9'),('', '')]