Warm tip: This article is reproduced from stackoverflow.com, please click
cucumber javascript regex

Ignore characters with regex in cucumber step definition

发布于 2020-05-01 17:30:41

I'm trying to capture the digits inside a value using regex whilst ignoring the characters.

Feature Step: Then the '1st' 'elementName' repeating group is displayed on the 'webPage' page

I want to take the '1' from the '1st' value and ignore the characters left in the string. As I have no use for the characters in what I'm trying to achieve.

Current Step Def:

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

Questioner
Grubsniff
Viewed
38
Greg Burghardt 2020-02-13 03:37

You need a back reference that captures the number, but omits the number suffix:

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

Also change [^"]* to [^']* in the other two back references, since you are using single quotes around the step arguments instead of double quotes.