python - 如何替换字符串中除方括号和反斜杠之外的所有标点符号?
问题描述
例如,如果我有
'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]'
解决方案
您可以简单地使用替换,如下所示:
my_str = 'define_your_string_here'
to_be_replaced = [':','\"','{','}']
for rep in to_be_replaced:
my_str = my_str.replace(rep, '')
推荐阅读
- javascript - Firefox 扩展 - 如何按类和标题单击按钮?
- android - “生成的签名包”构建过程卡在 :app:uploadCrashlyticsMappingFileRelease 任务
- javascript - JSON数据有什么问题?
- postgresql - 使用ansible在psql server上执行sql命令
- mysql - 具有静态开始时间的 SQL 中的持续时间
- lwc - How to get field values from record in js in lwc
- javascript - 如何在导入时动态映射列名
- postgresql - 如何避免 Aurora Postgres 因大量插入(选择...)查询而内存不足?
- c# - C# ZipArchive 压缩整个存档而不是
- django - 没有这样的列:AGC.id Django