ssss
ssss

Reputation: 573

Ruby regex seems to not see a `dash`

Ruby code:

Then /^I verify ([\w\s]+) table contains the following items on the page$/ do | page_table, table |
.......

Test:

Then I verify Customer-Level Templates table contains the following items on the page

When i run the test, it says Undefined step. I guess somehow the dash character in Customer-Level Templates is being ignored by ([\w\s]+). What is the regex so it could grab the whole Customer-Level Templates ?

Upvotes: 1

Views: 1958

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626738

You may add - to the character class:

/^I verify ([\w\s-]+) table contains the following items on the page$/

See a Rubular test.

Or make it even more generic by using .*? to match any 0+ chars other than line break chars, as few as possible:

/^I verify (.*?) table contains the following items on the page$/

See another Rubular test.

Note that in Ruby, ^ and $ match line boundaries. If you need to match the whole string, replace ^ with \A and $ with \z anchors.

Upvotes: 4

Related Questions