How do you use regular expressions in Cucumber?

We can use regular expressions in Cucumber for selecting a collection of similar statements in the feature file.


feature file

Feature: Exam Syllabus
Scenario Outline: Summer and Winter Exam Schedule
Given Exam time table in summer season
Given Mathematics and Physics Syllabus
Given Exam time table in winter season

The step Definition file has @Given("^Exam time table in ([^\"]*) season$") which maps two Given statements in a Feature file with the help of regular expression.


@Given ("^Exam time table in ([^\"]*) season$")
public void timeTable(String season){
   if (season.equals("winter")){
      System.out.println("The winter syllabus");
      System.out.println("The summer syllabus");
@Given ("^Mathematics and Physics Syllabus$")
public void syllabusList(){
   System.out.println("Mathematics and Physics syllabus is");

Updated on: 11-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started