Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么我的正则表达式在结束标记之前添加换行符?
string = '\s ప్రపంచ ప్రారంభం' re.sub(r'\\s (.*)', r'<h3>\1</h3>', string)
我得到了什么
<h3>ప్రపంచ ప్రారంభం </h3>
我想要的是
<h3>ప్రపంచ ప్రారంభం</h3>
查看字符串的文本部分,确保没有任何内容创建换行符。当我尝试时:
s = '\s hi world' re.sub(r'\\s (.*)', r'<h3>\1</h3>', s)
我有:
'<h3>hi world</h3>'
我使用的是 Python 2.7.3。