devroom.io/content/posts/2012-05-22-ruby-regex-scanning-in-a-case-statement.md

20 lines
507 B
Markdown
Raw Normal View History

2017-03-20 15:35:19 +00:00
+++
date = "2012-05-22"
title = "Ruby: regex scanning in a case statement"
tags = ["Ruby", "snippet"]
slug = "ruby-regex-scanning-in-a-case-statement"
+++
2015-03-26 11:28:08 +00:00
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.
2017-03-20 15:35:19 +00:00
``` ruby
case input
when /(.*)\stoday$/i then
puts "Today: #{$1}"
end
```
I think you can see how you can bend this to your own needs.
2015-03-26 11:28:08 +00:00