当前位置 : 主页 > 编程语言 > python >

python re.sub

来源:互联网 收集:自由互联 发布时间:2022-06-28
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("(?Pyear\d{4})-(?Pmonth\d{2})-(?Pday\d{2})",r"\gmonth/\gday/\gyear",str1) #'10/15/2017 this is happy day...
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...'

 


上一篇:python __set__ __get__ __delete__
下一篇:没有了
网友评论