尝试使用grep基本编辑JSON文件,目前我已经拥有
(?={\"expand)(.*?)(?= @)|(?=","component)(.*?)(?<=}})
这是查看字符串,并排除字符串“ @”之后和字符串“” component”之前的所有字符串(单词前面的引号)。 当我使用它时,我会一直保持第一部分(“ @”之前的所有内容,而不是““ component”之后的字符串)
我一直在搜索,但是发布的解决方案适用于具有多个字符串的文本,但是此JSON文件被视为一个巨大的完整字符串,因此它们无法正常工作。
已经尝试过的正则表达式,例如:
(?<!"component\.)$
JSON如下:
{
"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id":"191657",
"self":"http://localhost:8080/rest/api/2/issue/,
"key":"NIC1-159",
"fields":{
"summary":"HttpOnlyCookies_In_Config @ NOT NEEDED TEXT HERE",
"components":[
{
"self":"http://localhost:8080/rest/api/2/",
"id":"13218",
"name":"Nicktest"
}
],
"customfield_12900":"test.repo",
"description":"*HttpOnlyCookies_In_Config* issue exists @ *someothertext here",
"customfield_12320":null,
"priority":{
"self":"http://localhost:8080/rest/api/2/priority/",
"iconUrl":"http://localhost:8080/images/icons/priorities/major.svg",
"name":"2-Major",
"id":""
},
"customfield_12322":null
}
},
我想:
{
"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id":"191657",
"self":"http://localhost:8080/rest/api/2/issue/,
"key":"NIC1-159",
"fields":{
"summary":"HttpOnlyCookies_In_Config",
"components":[
{
"self":"http://localhost:8080/rest/api/2/",
"id":"13218",
"name":"Nicktest"
}
],
"customfield_12900":"test.repo",
"description":"*HttpOnlyCookies_In_Config* issue exists @ *someothertext here",
"customfield_12320":null,
"priority":{
"self":"http://localhost:8080/rest/api/2/priority/",
"iconUrl":"http://localhost:8080/images/icons/priorities/major.svg",
"name":"2-Major",
"id":""
},
"customfield_12322":null
}
},
请注意,“描述”处的第二个@并没有被清除。