用于替换双引号字符串中不同双引号组合的正则表达式

A regular expression to replace different combinations of double quotes inside a double-quoted string

用于替换双引号字符串中不同双引号组合的正则表达式。

无法用一个正则表达式(对于 PCRE)清除 JSON。只是不知道接下来要做什么。

("title":")[\s\S]+(", "partid":)

我尝试了各种搜索和替换选项。例如,("title":"[^"])(")([^"])(")(, "p) $1$3$4$5 ,然后两个双引号相同,三个,依此类推。

字符串示例:

{ "DT_RowId":"c2a839fb-580a-11e8-bac6-00155d080416", **"title":"Гайка 7/16"-14" UNC топорна;14H813;P88344 12""**, "partid":"S.4964", "manufacturerid":"2a7dc482-af13-11de-88d3-00e081b05e17", "manufacturer":"SPAREX", "quantity":">10", "price":"8.93", "actionprice":"", "rep":1, "img":0 } , { "DT_RowId":"05d8b40c-ec93-11dd-8f72-00e081b05e05", "title":"Нож ротора (зам.501060)", "partid":"501063", "manufacturerid":"3a7e891f-07ba-11de-8a95-00e081b05e17", "manufacturer":"Geringhoff", "quantity":">10", "price":"932.27", "actionprice":"584.90", "rep":1, "img":1 } , { "DT_RowId":"b7c6c9ee-adca-11e3-8202-00155d012119", **"title":"Олива моторна "CASTROL VECTON" 10W40 E4"/E7", 208L"**, "partid":"RB-V14E4E7-208L", "manufacturerid":"763d805e-c53b-11de-9210-00e081b05e05", "manufacturer":"CASTROL", "quantity":">10", "price":"111.60", "actionprice":"", "rep":1, "img":1 } , { "DT_RowId":"05d8b41d-ec93-11dd-8f72-00e081b05e05", **"title":"Н""о"ж"**, "partid":"501251", "manufacturerid":"3a7e891f-07ba-11de-8a95-00e081b05e17", "manufacturer":"Geringhoff", "quantity":">10", "price":"719.45", "actionprice":"", "rep":1, "img":1 }

请帮忙。请帮忙。如何删除或转义 "title":"", "partid":

之间的双引号

您可以使用

(?:\G(?!\A)|"title":").*?\K"(?=.*?"\s*,\s*"partid":)

替换为空字符串。参见 regex demo.

详情

  • (?:\G(?!\A)|"title":") - 上一场比赛结束或 "title":" 字符串
  • .*? - 任何 0+ 个字符,换行字符除外,尽可能少
  • \K - 匹配重置运算符
  • " - 一个 " 字符
  • (?=.*?"\s*,\s*"partid":) - 后跟任何 0+ 个字符,换行符除外,尽可能少,"、0+ 个空格、,、0+ 个空格和 "partid":.