如何替换字符串中的多个字符?
请帮助修复脚本
我需要在“名称”行中将特殊字符替换为短语“特殊字符”
newName = replace(name, ['\', '/', ':', '*', '?', '"', '<', '>', '|'], 'special char')
但我得到消息:
无效的语法
您可以使用re.sub():
import re
newName = re.sub('[\\\\/:*?"<>|]', 'special char', name)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句