我是自动化新手!我使用wdio5、黄瓜和selenium框架和gherkin语言。我需要为需要添加这些模式的gherkin特性使用JavaScript编写一个步骤文件。
示例
52.27 .27 2.27
我希望我问得对!房子里的初级开发商
帮助
发布于 2022-07-28 23:59:50
如果我正确理解,您需要一个regex模式来匹配您共享的数字。
下面是这样一种模式的一个例子:
/^[-+]?((\.\d+)|(\d+(\.\d+)?))$/其中,[-+]?与领先的+/-符号匹配,(\.\d+)用leadiinig .匹配数字,(\d+(\.\d+)?)匹配完整的数字。
应该与以下数字相匹配:'-1', '+1', '50', '.27', '2.27'
片段:
const testNumbers = ['-1', '+1', '50', '.27', '2.27'];
const pattern = /^[-+]?((\.\d+)|(\d+(\.\d+)?))$/;
const isAllMatched = testNumbers.every(testNumber => testNumber === testNumber.match(pattern)?.[0]);
console.log('isAllMatched: ', isAllMatched);
https://stackoverflow.com/questions/73159774
复制相似问题