Javascript 如何从Cumber步骤中捕获正则表达式
我需要在每个步骤中捕获基于正则表达式的值 用例=>Javascript 如何从Cumber步骤中捕获正则表达式,javascript,regex,gherkin,cucumberjs,Javascript,Regex,Gherkin,Cucumberjs,我需要在每个步骤中捕获基于正则表达式的值 用例=> When I click the '2nd' item in the list 我想在上面的步骤定义中捕捉“2” 我在步骤定义=> When(/^I click the '\d{1,2}(?:st|nd|rd|th)?' item in the list$/, async function(element) { await helperActions.clickTopBanksListElement(element); }); 但无
When I click the '2nd' item in the list
我想在上面的步骤定义中捕捉“2”
我在步骤定义=>
When(/^I click the '\d{1,2}(?:st|nd|rd|th)?' item in the list$/, async function(element) {
await helperActions.clickTopBanksListElement(element);
});
但无法捕获“2”。任何人,请建议你只需要用括号捕捉数字:
'(\d{1,2})(?:st | nd | rd | th)'
此外,您不需要将数字限制为一个或两个字符。使用(\d+)
将捕获一个或多个数字。我也不知道您为什么试图在st、nd、rd和th缩写的反向引用开头包含?:
字符
When(/^I click the '(\d+)(st|nd|rd|th)?' item in the list$/, async function(element) {
await helperActions.clickTopBanksListElement(element);
});
或者,您不需要引号:
When(/^I click the (\d+)(st|nd|rd|th)? item in the list$/, async function(element) {
await helperActions.clickTopBanksListElement(element);
});
给你:
When I click the 2nd item in the list
这看起来更像是你如何写这个句子。你只需要用括号捕捉数字:
'(\d{1,2})(?:st | nd | rd | th)?'
此外,您不需要将数字限制为一个或两个字符。使用(\d+)
将捕获一个或多个数字。我也不知道您为什么试图在st、nd、rd和th缩写的反向引用开头包含?:
字符
When(/^I click the '(\d+)(st|nd|rd|th)?' item in the list$/, async function(element) {
await helperActions.clickTopBanksListElement(element);
});
或者,您不需要引号:
When(/^I click the (\d+)(st|nd|rd|th)? item in the list$/, async function(element) {
await helperActions.clickTopBanksListElement(element);
});
给你:
When I click the 2nd item in the list
你可以使用一个捕获组
(\d{1,2})
对,给定(/^I单击列表中的“(\d{1,2})(?:st | nd | rd | th”)项($/,(item)=>{…})
`您可以使用捕获组(\d{1,2})
对,给定(/^I单击列表$/,(item)=>{…}中的“(\d{1,2})(?:st | nd | rd | th)项)代码>`