【问题标题】:Postman regexp - SyntaxError: Invalid or unexpected token邮递员正则表达式 - SyntaxError:无效或意外的令牌
【发布时间】:2021-01-10 22:47:01
【问题描述】:

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

邮递员测试脚本:

    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 在尝试执行测试脚本时返回以下错误: There was an error in evaluating the test script: SyntaxError: Invalid or unexpected token

【问题讨论】:

    标签: javascript rest postman


    【解决方案1】:

    这个错误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" );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 2021-09-21
      • 2020-07-12
      • 2017-09-29
      • 2018-12-03
      • 2021-08-14
      • 1970-01-01
      相关资源
      最近更新 更多