Last updated

Ruby: regex scanning in a case statement

Here’s a handy ruby snippet that might come in handy one day.

When the regex matches (input should end with " today"), you can directly grab the matched value using the special $1 variable.

1case input
2when /(.*)\stoday$/i then
3  puts "Today: #{$1}"
4end

I think you can see how you can bend this to your own needs.