Ruby: regex scanning in a case statement
22 May, 2012
1 minute read

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.

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

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

If you're seeing this message you've probably enabled some form of adblocker. I respect that.

I use this space to show recommended books on in relation to the post you just read. This generates a small income that allows me to buy a book every now and then.