python re.sub

str1="2017-10-15 this is happy day..."
>>> re.sub("(\d{4})-(\d{2})-(\d{2})",r"\2/\3/\1",str1)
##'10/15/2017 this is happy day...'
>>> re.sub("(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})",r"\g<month>/\g<day>/\g<year>",str1)
#'10/15/2017 this is happy day...'

 

posted @ 2018-03-17 09:50  howhy  阅读(123)  评论(0编辑  收藏  举报