温馨提示:本文翻译自stackoverflow.com,查看原文请点击:javascript - Ignore characters with regex in cucumber step definition
cucumber javascript regex

javascript - 忽略 Cucumber 步骤定义中的正则表达式字符

发布于 2020-05-01 23:50:46

我正在尝试使用正则表达式捕获值内的数字,而忽略字符。

功能步骤:然后,在“ webPage”页面上显示“ 1st”“ elementName”重复组

我想借此“1”从“1”值,而忽略离开了字符串中的字符。因为我没有用到我想要达到的目标。

当前步骤定义:

Then(/the 'areaINeedHelp' '([^"]*)' repeating group is displayed on the '([^"]*)' page

查看更多

提问者
Grubsniff
被浏览
16
Greg Burghardt 2020-02-13 03:37

您需要一个可以捕获数字但没有数字后缀的后向引用:

Then(/the '(\d+).{2}' '([^']*)' repeating group is displayed on the '([^']*)' page/

还要更改[^"]*[^']*其他两个反向引用,因为您在step参数周围使用单引号而不是双引号。