使用索引为0,1….N的正则表达式获取不带括号的值。以下是代码-
var regularExpression= /(?<=\[).*?(?=\])/g;
var getTheValueWithIndex= "[John Smith][David
Miller]".match(regularExpression);
console.log("The first value without bracket="+getTheValueWithIndex[0]);
console.log("The second value without
bracket="+getTheValueWithIndex[1]);要运行以上程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo132.js。
输出结果
这将产生以下输出-
PS C:\Users\Amit\JavaScript-code> node demo132.js The first value without bracket=John Smith The second value without bracket=David Miller