如何将正则表达式用于茉莉花匹配器 [英] How to use regex for jasmine matchers
本文介绍了如何将正则表达式用于茉莉花匹配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要验证文本标签,但是它包含动态部分,因此我尝试使用正则表达式,但是它不起作用.
I need to verify the text label but it contains dynamic part, so I try to use regex but it doesn't work.
expect(aboutPage.userInterfaceText.getText()).toMatch('/- User Interface: v \d+\.\d+\.\d+/');
我总是会遇到下一个错误:
I always get next error:
- Expected '- User Interface: v 4.4.63' to match '/- User Interface: v d+.d+.d+/'.
推荐答案
- Expected '- User Interface: v 4.4.63' to match '/- User Interface: v d+.d+.d+/'.
您可以看到,模式两端的斜杠也包含在表达式中,但是您的- User Interface: v 4.4.63
测试字符串不包含斜杠.
As you can see the slashes at both ends of the pattern are also included into the expression, but your - User Interface: v 4.4.63
test string does not contain the slashes.
您不应将正则表达式括在单引号中,以使其成为在控制台上为我工作:
> 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"]
这篇关于如何将正则表达式用于茉莉花匹配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文