0% found this document useful (0 votes)
698 views

Cucumber Regular Expressions Cheat Sheet

Cucumber uses regular expressions to capture a substring for a step definition argument. Regular expressions can be used with parentheses to include an or in a larger pattern. Cucumber is a regular expression language.

Uploaded by

João Silva
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
698 views

Cucumber Regular Expressions Cheat Sheet

Cucumber uses regular expressions to capture a substring for a step definition argument. Regular expressions can be used with parentheses to include an or in a larger pattern. Cucumber is a regular expression language.

Uploaded by

João Silva
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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

.*

any character (except a newline) 0 or more times

.+ .{2}

at least one of anything (except a newline) exactly two of any character

.{1,3}

one to three of any character

^pattern pattern$ [0-9]* or \d*

anchors match to beginning of string anchors match to end of string matches a series of digits (or nothing)

[0-9]+ or \d+ "[^\"]*"

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)

See http://www.richardlawrence.info/2010/07/20/just-enough-regular-expressions-for-cucumber/ for more examples and explanations.

Copyright 2010-2011 Humanizing Work Reproduction permitted, other rights reserved

You might also like