Regex 使用带有动态值的正则表达式搜索字符串的一部分

Regex 使用带有动态值的正则表达式搜索字符串的一部分,regex,Regex,我有这个字符串: {"rendererOptions":{"localeStrings":{"renderError":"An error occurred rendering the PivotTable results.","computeError":"An error occurred computing the PivotTable results.","uiRenderError":"An error occurred rendering the PivotTable UI.","s

我有这个字符串:

{"rendererOptions":{"localeStrings":{"renderError":"An error occurred rendering the PivotTable results.","computeError":"An error occurred computing the PivotTable results.","uiRenderError":"An error occurred rendering the PivotTable UI.","selectAll":"Select All","selectNone":"Select None","tooMany":"(too many to list)","filterResults":"Filter values","apply":"Apply","cancel":"Cancel","totals":"Totals","vs":"vs","by":"by"},"rowSubtotalDisplay":{"hideOnExpand":true}},"localeStrings":{"renderError":"An error occurred rendering the PivotTable results.","computeError":"An error occurred computing the PivotTable results.","uiRenderError":"An error occurred rendering the PivotTable UI.","selectAll":"Select All","selectNone":"Select None","tooMany":"(too many to list)","filterResults":"Filter values","apply":"Apply","cancel":"Cancel","totals":"Totals","vs":"vs","by":"by"},"derivedAttributes":{},"hiddenAttributes":[],"hiddenFromAggregators":[],"hiddenFromDragDrop":[],"menuLimit":500,"cols":["clientname","industry"],"rows":["country"],"vals":[],"rowOrder":"key_a_to_z","colOrder":"key_a_to_z","exclusions":{},"inclusions":{},"unusedAttrsVertical":85,"autoSortUnusedAttrs":false,"onRefresh":null,"showUI":true,"sorters":{},"rendererName":"Table With Subtotal","inclusionsInfo":{},"aggregatorName":"Count"}
在这里,我想提取字符串中以单词
cols:[]
开头的部分。方括号内的值将是动态的,并用双引号括起来。例如,在上面的例子中,我想要得到的字符串是:
“cols”:[“clientname”,“industry”]
。注意:我无法控制方括号内的值的数量

我编写了这个正则表达式:
(“cols”:\[(“\w*”,*\])(cols:\[“\w*”\]*)
但很明显,我做错了什么。我需要一些提示来匹配方括号内的1个或多个值

试试这个! Regex:

.*\"cols\":\[\"([^:]+)\"\]
输出:

谢谢您的格式化。我本应该小心规则的。没有借口。我知道。我想你需要做的是使用JSON解析器,不要再试图用正则表达式来混淆它。