When I have a very long regex, like a cucumber step definition, what would be the best way to line wrap it?
example, i would like something like:
When /^I have a very long step definition here in my step definition file$/ do
...
end
break up into two lines (this doesnt work:)
When /^I have a very long step definition here in /\
/my step definition file$/ do
...
end
If you're here specifically for cucumber, using cucumber expressions is a great alternative to regexes
You can use a verbose regex with the /x
modifier, but then you need to make spaces explicit because they will otherwise be ignored. Another advantage is that this allows you to comment your regex (which, if it's long, might be a good idea):
/^ # Match start of string
I[ ]have[ ]a[ ]very[ ]long[ ]
step[ ]definition[ ]here[ ]
in[ ]my[ ]step[ ]definition[ ]file
$ # Match end of string
/x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With