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
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.
Thank you so much!! I've been trying this for too long hah. Out of interest why do you suggest changing the [^"]* to [^']* as this is working for me no problem currently.
Because
[^"]*
means **any non-double quote character zero or more times, and your regular expression was denoting arguments with single quotes. It only worked by coincidence. If you had specified a page name that contained a double quote then the regex would not have matched the full page name.