I'm trying to extract dates out of a string using python. The date is in the format mm-dd-yyyy. So I know the regex should be something like /d{2}-/d{2}-/d{4}. However when I try and iterate over the array below I am not able to extract the dates out of the string.
import re
logs = ["First entry to journal logs. (01-01-2015)", "Last entry to journal logs 07-01-2016"]
for i in logs:
m = re.match("/d{2}-/d{2}-/d{4}",i)
print m.group(0)
I haven't work with re before so not sure if I'm using it properly.
\, not/. To extract all matches usere.findall.\dnot/drbefore the string so that it'sr"\d{2}-\d{2}-\d{4}"searchinstead ofmatch. The latter is anchored at the start of the string such that your regex becomes^\d{2}-\d{2}-\d{4}, while the former searches anywhere in the string