码迷,mamicode.com
首页 > 编程语言 > 详细

python re.sub

时间:2018-03-17 10:44:54      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:python   pos   str1   sub   post   ...   color   class   body   

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 re.sub

标签:python   pos   str1   sub   post   ...   color   class   body   

原文地址:https://www.cnblogs.com/howhy/p/8587559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!