I am looking to strip dates out of a list of longer strings, each of which, may or may not, contain a date. An example of one such string might be:
"Jane Doe 76554334 12/15/2017 - 8:35 pm 700945 - SDFTRD $550.95"
I have built a method which is returning an error:
AttributeError: 'NoneType' object has no attribute 'match_object'
My aim has been to look for regex matches on (\d+/\d+/\d+) and then convert that match to a string so that it can be used with .replace(). I cannot seem to solve this using match_object.
Here is my method:
def replace_match(string):
match=re.search(r'(\d+/\d+/\d+)',string)
if match:
match=re.match(r'(\d+/\d+/\d+)',string).match_object.group(0)
print("match = " + match)
string = string.replace(match, "")
else:
print("no match found")
return string
I am using Python 3.6.3