javascript - postman 正则表达式 - 语法错误 : Invalid or unexpected token

标签 javascript rest postman

我正在尝试编写 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/

相关文章:

java - HtmlUnit 的 HtmlPage.getElementById 似乎在多次调用后重新初始化 JavaScript

ios - 从 Swift 函数中的异步调用返回数据

python - 如何将模型方法暴露给 django-rest-framework

json - 可以使用 curl 上传外部 json 文件而不是 --data 吗?

javascript - 优先级-web-sdk : Specific number of rows

javascript - 滚动事件触发太早

javascript - ReactJs 正确导入 ckeditor 配置 - CORS

rest - 如何使用 Postman 对 Django REST Framework 进行身份验证

java - 使用 "helm test"集成测试部署的服务

json - POSTMAN - 从 JSON 响应中保存属性值