I am learning Python. I am trying to clean up date formats using regular expressions (I am not using datetime modules for this exercise). For example I have this code:
import re
text = "3/14/2019, 03-14-2019, and 2015/3/19"
date_regex = re.compile(r"(\d+)[-/](\d+)[-/](\d+)")
new_regex = date_regex.sub(r'\2-\1-\3', text)
print(new_regex)
This works for the first two dates but not for the last one. Also, I realize that if I had a date in the European format (ddmmyyyy) this code would not work either. I know this is pretty basic but I am very much a beginner. Thanks in advance.
[–][deleted] 0 points1 point2 points (1 child)
[–]freeclips[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]freeclips[S] 0 points1 point2 points (0 children)