[Solved] Replace YYYY-MM-DD dates in a string with using regex [closed]


import re
from datetime import datetime, timedelta

dateString = "hello hello 2017-08-13, 2017-09-22"

dates = re.findall('(\d+[-/]\d+[-/]\d+)', dateString)

for d in dates:
    originalDate = d

    newDate = datetime.strptime(d, "%Y-%m-%d") 
    newDate = newDate + timeDelta(days=5)
    newDate = datetime.strftime(newDate, "%Y-%m-%d")   

    dateString = dateString.replace(originalDate, newDate)

Input: hello hello 2017-08-13, 2017-09-22

Output: hello hello 2017-08-18, 2017-09-27

6

solved Replace YYYY-MM-DD dates in a string with using regex [closed]