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.
我有一个文件,需要进行一些替换:将“,”替换为“,”,并将所有其他不在 rule2 中的字符替换为空格,我该怎么做?</p>
那这个呢?
text = text.replace(",", ",")
您可以使用正则表达式模块:
text = re.sub(',', ',', text) text = re.sub(negated_rule2, ' ', text)
您对“rule2”的否定使用正则表达式语法格式化(参见上面的链接)。