【问题标题】:finding unique multiple similar strings of json between {}在 {} 之间找到唯一的多个相似的 json 字符串
【发布时间】:2017-08-07 18:07:02
【问题描述】:

我正在尝试在 python 脚本的字符串中匹配多组未引用/无效的 json。

这是我试图解析的字符串示例

string = ' json.piece({ id:001, dictionary_id:0013, weight:"10" }); json.piece({ id:002, dictionary_id:0075, weight:"01" }); json.piece({ id:007, dictionary_id:0010, weight:"54" });'

我目前的正则表达式是:

result = re.findall(r"(\{[^}]*\})", string)

它没有找到单独的部分,而是找到了整个字符串,因为它在技术上也是正确的,但我尽管通过 stackoverflow 进行了拖网,但似乎找不到解决方案

【问题讨论】:

标签: python json regex string


【解决方案1】:

您可以使用(\{[^}]*?\}) 使您的regex 不贪婪

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 2021-10-12
    • 2019-01-26
    • 1970-01-01
    相关资源
    最近更新 更多