Javascript string.match,带有特定前缀和后面的文本

Javascript string.match,带有特定前缀和后面的文本,javascript,regex,Javascript,Regex,也许有人能帮我从字符串中获取零件数据 let input1: string = "any string before specialPrefix: ['content1', 'content2'] and any other text after"; let input2: string = "any string before specialPrefix:['content1', 'content2'] and any other text after"; let input3: st

也许有人能帮我从字符串中获取零件数据

let input1: string = "any string before specialPrefix: ['content1', 'content2'] and any other text after";  
let input2: string = "any string before specialPrefix:['content1', 'content2'] and any other text after";  
let input3: string = "any string before specialPrefix: 'content1', 'content2' and any other text after";  
期望

output1,output2:具有两个值的数组, “content1”和“content2”。 输出3:空数组

您可以使用/specialPrefix:\s*\[.*.\]/

让输入=[specialPrefix之前的任何字符串:['content1','content2']和之后的任何其他文本,specialPrefix之前的任何字符串:['content1','content2']和之后的任何其他文本,specialPrefix之前的任何字符串:['content1','content2'和之后的任何其他文本]; var result=inputs.mapstr=>/specialPrefix:\s*\[.*.\]/.execstr\\[[1];
console.logresult;尝试此/\[.\]/regexit将在“任何数据[某些文本]”上失败-预期结果为空。据我所知,我的问题看起来很愚蠢。不幸的是,我不能创建这种正则表达式。实际上,你的问题不清楚,这里的具体前缀是什么?它是预定义的文本。在样本中,它等于“specialPrefix:”对于上述情况,它是specialPrefix吗?