【问题标题】:Need to match from json only values with quotes using regex需要使用正则表达式仅从 json 值与引号匹配
【发布时间】:2019-03-31 04:39:47
【问题描述】:

我正在尝试匹配来自任何 json 的所有值。 我现在的正则表达式是/: ('|").*?('|")(?=,)?/g 我只需要使用 qoutes 获得价值,但也需要获得冒号。 https://www.regextester.com/99141 有什么建议吗?

【问题讨论】:

  • 我的问题很简单。需要使用正则表达式仅从 json 值与引号匹配。是的,使用正则表达式。我正在使用 rainbow.js 并且需要更改所有值的颜色。在 html 中我得到 json 文件,所以需要匹配所有值并添加类。

标签: javascript json regex


【解决方案1】:

做了一些工作,但我认为这似乎是pass the tests I've thrown at it

/("[^"\\]*(?:\\.[^"\\]*)*")(?=,|\s*(]|}))/g

它似乎适用于缩小和美化的 JSON 字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多