我有以下字符串,我想用10
替换(abc +0.5)*3
Test_String= 'I am not able to replace (abc+0.5)*3'
我试过以下方法
re.sub('\\b(abc\\+0.5)\\*3\\b','10',Test_String)
re.sub('\\b\\(abc\\+0.5\\)\\*3\\b','10',Test_String)
但似乎什么都不起作用,我正在使用边界,因为我想替换精确匹配
I am not able to replace 10
I am not able to replace (abc+0.5)*3
我做错了什么
你可以
\\+
变成\+
\b
,因为在打开的括号旁边没有单词边界(可以保留关闭的括号)\.
(可选,因为它代表任何字符)相关问题 更多 >
编程相关推荐