Cucumber Regular Expressions Cheat Sheet
Cucumber Regular Expressions Cheat Sheet
Pattern . Notes one of anything (except a newline) a B 3 a AbCD words with punctuation! 123-456 an empty string all of the above except the empty string aa Ab !n 23 aa Ab !n2 9 /^foo/ matches foo and foo bar but not bar foo /foo$/ matches foo and bar foo but not foo bar 123456 9 an empty string all of the above except the empty string "foo" "foo bar" "12345" /an?/ matches a and an but not n /Im|I am/ matches Im and I am /I (eat|ate)/ matches I eat and I ate /(\d+) users/ matches 3 users and captures the 3 for use later /I (?:eat|ate)/ matches I eat and I ate but does not capture eat or ate for use later Match Examples
.*
.+ .{2}
.{1,3}
anchors match to beginning of string anchors match to end of string matches a series of digits (or nothing)
matches one or more digits matches something (or nothing) in double quotes; literally, any character except a double quote zero or more times inside double quotes makes the previous character or group optional like a logical OR; can be used with parentheses to include an OR in a larger pattern a group; typically used in Cucumber to capture a substring for a step denition argument a non-capturing group
? |
(pattern)
(?:pattern)