【发布时间】:2017-05-28 11:55:32
【问题描述】:
我试图在 python 中使用正则表达式将日期插入字符串
link = 'branch=;deps=;date=;rev=;days=1;user='
date = "10.12.2016"
re.sub(r'(.*)(date=[^;]*)(.*)','\\1\\2'+date+'\\3',link)
我期待输出是
'branch=;deps=;date=10.12.2016;rev=;days=1;user='
但我得到了这个,
'branch=;deps=;**\x88.12.2016**;rev=;days=1;user='
另一件事,如果我在日期变量中有一些字符串,它可以替换就好了。
date="hello"
re.sub(r'(.*)(date=[^;]*)(.*)','\\1\\2'+date+'\\3',link)
给予,
'branch=;deps=;**date=hello**;rev=;days=1;user='
这可能是什么问题?
【问题讨论】:
标签: python regex python-2.7 text-processing