I need help with replacing characters in a string using regular expressions.
Input :
s3 = ['March/21/2019' , 'Mar/23/2019']
Desired Output :
s3 = ['03/21/2019' , '03/23/2019']
I tried a few things, but none work:
s3[i] = s3[i].replace(r'Mar[a-z]*', '03')s3[i] = s3[i].replace(r'(?:Mar[a-z]*)', '03')
datetime: stackoverflow.com/questions/2265357/…replaceisn't using regexes. You needre.sub(r'Mar[a-z]*', '03',s3[i])import reand use it instead ofstr.replace(), which doesn't support regex patterns. If your data list is part of a pandas dataframe though, you could usedf.str.replace(), which in turn supports them.