I am trying to search different types of dates in my strings using regex.
import re
txt1 = "The date is 3-Dec "
txt2 = "The date is3-Dec "
txt3 = "The date is 3-Dec"
txt4 = "The date is Dec-20"
txt5 = "The date isDec-20"
regx = r"(?:\d{2}|\d{1}|\d{0})(?:[,| ,|, |-|/|\\|\s|\d{0}])(?:%s)(?:[,| ,|, |-|/|\\|\s|\d{0}])(?:\d{4}|\d{2}|\d{0})" % '|'.join(['Nov', 'Dec'])
x1 = re.findall(regx, txt1)
print(x1)
x2 = re.findall(regx, txt2)
print(x2)
x3 = re.findall(regx, txt3)
print(x3) # empty
x4 = re.findall(regx, txt4)
print(x4)
x5 = re.findall(regx, txt5)
print(x5) # empty
Could someone help why txt3 and txt5 are not working? Basically following portion of regex is not working when there is no leading or trailing space for date (?:[,| ,|, |-|/|\\|\s|\d{0}])