我需要一个正则表达式来匹配:
["4","0","2"]
["4564","320","452"]
["23"]
我在REGEXR上测试了一个正则表达式,并且在那里工作正常。 https://regexr.com/3sab5
所以,我用JavaScript编写了它:
let ar_value = '["4564","320","452"]';
let pattern = '^\[(,?"[0-9]+")+\]$';
let matches = ar_value.match(pattern);
console.log(matches);
但这会导致错误:
Uncaught SyntaxError: Invalid regular expression: /^[(,?"[0-9]+")+]$/: Unmatched ')'
有人可以告诉我我在做什么错?
非常感谢!
let ar_value = '["4564","320","452"]';
let pattern = '^\[(,?"[0-9]+")+\]$';
let matches = ar_value.match(pattern);
console.log(matches);