首页 > 解决方案 > 如何替换字符串中除方括号和反斜杠之外的所有标点符号?

问题描述

例如,如果我有

'address": [{"type": null, "value": "1600 Amphitheatre Parkway\nMountain View\nCA\n94043\nUnited States"}]',

我希望它是这样的

'address [type null value 1600 Amphitheatre Parkway\nMountain View\nCA\n94043\nUnited States]'

标签: python

解决方案


您可以简单地使用替换,如下所示:

my_str = 'define_your_string_here'
to_be_replaced = [':','\"','{','}']
for rep in to_be_replaced:
    my_str = my_str.replace(rep, '')

推荐阅读