我正在尝试编写 Postman 测试并使用正则表达式验证个人身份证号码。我已经验证了正则表达式:\b((([0-2]{1}[0-9]{1}|[3]{1}[0-1]{1})[0-9] {1}[0-9]{1}[0-9]{1}[0-9]{1}(.|\n|\t|)[0-9]{5})|[3] {1}[2]{1}[0-9]{4}(.|\n|\t|)[0-9]{5})\b
postman 测试脚本:
var req = JSON.parse(pm.request.body.raw);
pm.expect(req.personnumber).to.match( \b((([0-2]{1}[0-9]{1}|[3]{1}[0-1]{1})[0-9]{1}[0-9]{1}[0-9]{1}[0-9]{1}(.|\n|\t|)[0-9]{5})|[3]{1}[2]{1}[0-9]{4}(.|\n|\t|)[0-9]{5}\b), "wwww" );
});
Postman 在尝试执行测试脚本时返回以下错误:
评估测试脚本时出错:SyntaxError: Invalid or unexpected token
最佳答案
此错误 SyntaxError: Invalid or unexpected token
来自于您忘记了正则表达式开头和结尾的 /
:
pm.expect(req.personnumber).to.match( /\b((([0-2]{1}[0-9]{1}|[3]{1}[0-1]{1})[0-9]{1}[0-9]{1}[0-9]{1}[0-9]{1}(.|\n|\t|)[0-9]{5})|[3]{1}[2]{1}[0-9]{4}(.|\n|\t|)[0-9]{5}\b)/, "wwww" );
关于javascript - postman 正则表达式 - 语法错误 : Invalid or unexpected token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64049885/