我使用正则表达式从网页中获取字符串,并且该字符串的一部分可能包含我想替换为其他内容的内容。这怎么可能呢?我的代码是这样的,例如:
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'