Search code examples
javaregexcucumbergherkin

Cucumber detects to many arguments


I want to detect a list of Apps named AppA, AppB and AppC in my cucumber step.

i.e. "Given there are 2 badges in the repository owned by AppA,AppB"

I already tried the following and it works according to the IntelliJ colouring syntax :

@Given("^there are (\\d+) badges in the repository owned by (App[ABC](,App[ABC])*)$")

But at compilation the following error

However, the gherkin step has 3 arguments [2, AppA,AppB, ,AppB].

I think it is caused by the parenthesis within the parenthesis of the regex. Does anyone could share me a workaround so I get only [2, AppA,AppB] ?


Solution

  • I solved the issue using the non-capturing groupe ?:

    @Given("^there are (\\d+) badges in the repository owned by (App[ABC](?:,App[ABC])*)$")

    It seems that cucumber takes everything that is in capturing groups, even if they are nested (even if some regex checker tools only detect 1 for the list)