python - How to change date format of a date inside a string? -
this question has answer here:
i have string "hello please change date 04/24/2017 putting month in middle"
class paragraph: @staticmethod def change_date_format(paragraph): return none print(paragraph.change_date_format('hello please change date 04-24-2017 putting month in middle'))
i need change "hello please change date 24/04/2017 putting month in middle"
import re def change_date_format(paragraph): return re.sub('(\d+)/(\d+)/(\d+)', lambda m: '{}/{}/{}'.format(m.group(2), m.group(1), m.group(3)), paragraph)
this finds sequence of 3 groups of digits separated slashes (like 04/27/2017), uses format
swap first , second group.
Comments
Post a Comment