Skip to main content

Cannot create a new step, similar to an existing step



  • Sam Shackleton


    My knowledge of regex is a bit hazy but I believe the problem is that (.*) will capture as many characters as it can (it is greedy).

    I find regex101 to be very helpful when trying to troubleshoot these issues.

    Here is the starting point:

    We can see the problem you described above. Any time you try to use either of the new steps the text will be matched by the regex of your existing step and SpecFlow will invoke your original step with 2 parameters rather than one of the new steps with 3 parameters.

    .* is going to match any character (including apostrophes) 0 or more times, and capture as many characters as it can. This is why the following gets matched by one of the two capturing groups: 'foo' at position 'bar'.

    We can change the capturing group to match any character other than apostrophes 0 or more times:

    I think that might work although I haven't tried in SpecFlow.

    Another option I thought might work is to try is changing the capturing group to (.*?). The question mark at the end makes the group lazy. This means the fewest number of characters will be matched.

  • Brett Roberts

    Thankyou for the response and suggestions. Very Helpful.

    I will investigate that.

    I'm sure I'm not the only one who has encountered this issue.


Please sign in to leave a comment.

Powered by Zendesk