如何将正则表达式用于茉莉花匹配器
发布时间:2020-12-14 06:01:14 所属栏目:百科 来源:网络整理
导读:我需要验证文本标签,但它包含动态部分,所以我尝试使用正则表达式,但它不起作用. expect(aboutPage.userInterfaceText.getText()).toMatch('/- User Interface: v d+.d+.d+/'); 我总是得到下一个错误: - Expected '- User Interface: v 4.4.63' to matc
我需要验证文本标签,但它包含动态部分,所以我尝试使用正则表达式,但它不起作用.
expect(aboutPage.userInterfaceText.getText()).toMatch('/- User Interface: v d+.d+.d+/'); 我总是得到下一个错误: - Expected '- User Interface: v 4.4.63' to match '/- User Interface: v d+.d+.d+/'. 解决方法
正如您所看到的,模式两端的斜杠也包含在表达式中,但您的 – 用户界面:v 4.4.63测试字符串不包含斜杠. 您不应将正则表达式括在单引号中以使其成为valid regular expression object: expect(aboutPage.userInterfaceText.getText()).toMatch(/- User Interface: v d+.d+.d+/); 在控制台上为我工作: > var s = "- User Interface: v 4.4.63"; > var re = /- User Interface: v d+.d+.d+/; > s.match(re) ["- User Interface: v 4.4.63"] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |