我使用正则表达式从网页中获取字符串,并且该字符串的一部分可能包含我想替换为其他内容的内容。这怎么可能呢?我的代码是这样的,例如:
stuff = "Big and small"
if stuff.find(" and ") == -1:
# make stuff "Big/small"
else:
stuff = stuff
>>> stuff = "Big and small"
>>> stuff.replace(" and ","/")
'Big/small'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句