在JSON文件中用正则表达式查找并替换引号内的引号 [英] find and replace quotes inside quotes with regular expression in a JSON file

查看:440
本文介绍了在JSON文件中用正则表达式查找并替换引号内的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的JSON文件,其中包含近30000条记录. 一条记录如下所示:

I have a very large JSON file with almost 30000 records. One record looks something like this:

{
  "adlibJSON": {
    "recordList": {
      "record": [
        {
          "@attributes": {
            "priref": "4372",
            "created": "2011-12-09T23:09:57",
            "modification": "2012-08-11T17:07:51",
            "selected": "False"
          },
          "acquisition.date": [
            "1954"
          ],
          "documentation.title": [
            "A lot of text with a lot of extra double quotes like "this" and "this""
          ] ... ...

问题在于其中包含很多带有多余双引号的值.这可以是1个双引号,也可以是2或3个额外的双引号.请参见示例中的"documentation.title"值.

The problem is that there are a lot of values with extra double quotes in it. This can be 1 double quote, but also 2 or 3 extra double quotes. See the value of "documentation.title" in my example.

我如何找到所有这些引号并将其替换为正则表达式. 我使用sublime text 2做正则表达式,但是我不知道如何解决这个特定问题.

How do i find all these quotes and replace them with regular expression. I use sublime text 2 to do my regular expression, but i don't know how to solve this specific problem.

推荐答案

以下是两个示例:

这些具有以下要求:

  • 值的开头不是逗号,冒号,右括号或空格.

否则,您必须对其进行改进.第二个甚至允许值以空格开头,但也可能会有其他副作用...

Otherwise you have to improve it. The second one even allows values to start with a whitespace, but may also have some other side-effects ...

示例1:

\"[A-Za-z0-9][^"]+\"\s*[^,:}\s]

示例2:

\"([A-Za-z0-9\s][^"]+\"\s*[^,:\]}\s]){2}

这篇关于在JSON文件中用正则表达式查找并替换引号内的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆