I am trying to write code that clean up dates in different date formats (such as 3/14/2015, 03-14-2015, and 2015/3/14) by replacing them with dates in a single, standard format. So far I have wrote my regex expression but it's not working the way I would like.
import pyperclip,re
dateRegex = re.compile(r'''
(\d|\d{2}|\d{4}) # match 1 digit, or two digits, or four digits
(\s|-|\.|\/) # match either a space or a dash or a period or a backslash
(\d{2}|\d) # match either 2 digits or one
(\s|-|\.\/) # match either a space or a dash or a period or a backslash
(\d{4}|\d{2}) # match either 4 or 2 digits.
''',)
text = "12/25/0000, 10.21.1955, 10-21-1985 6-5-1995 2004/2/21 5/25/2111 4999.2.21 "
a = dateRegex.findall(text):
Any idea why this isn't working?
python-dateutil? Also it's "digits", FYI.findall. I hope these are all just mistakes made when copying the code. Likewise, I hope those comments for each line are just for SO demonstrative purposes and not actually in your code because those wouldn't be parsed as comments but rather part of the pattern.