分割这个字符串的正则表达式是什么?

What would be the regular expression to split this string?

我有这个:

st = '"a": "hello", "c": "another, string, with multiple", "b": "hello, world"'

我想用空 space 替换逗号,但只有在逗号前面的字符不是双引号 (")

时才应将其删除

所以 st 的结果是

st = '"a": "hello", "c": "another string with multiple", "b": "hello world"'

如果我理解你的问题,我认为我的伪代码将帮助你用你需要的语言解决你的问题

for i in st 
    if (st[i] = ",") AND (st[i-1] NOT """)
        POP
    else 
        return 

您的字符串看起来像 JSON,但去掉了周围的大括号。

最好是获取原始 JSON 并使用它,但如果您无法访问它,则恢复 JSON、解析它、进行替换,再次将其编码为 JSON,并再次去除那些大括号:

import json

st = '"a": "hello", "c": "another, string, with multiple", "b": "hello, world"'

d = json.loads("{" + st + "}")
for key in d:
    d[key] = d[key].replace(",", " ").replace("  ", " ")

st = json.dumps(d)[1:-1]