Is there a way to make this work correctly with a case when?
field = "head_count_2011_10_75"
case field
when match(/head_count_\d{4}_\d{1,2}_\d{1,4}/i)
puts "regex 1"
when match(/dmi_\d{4}_\d{1,2}_\d{1,4}/i)
puts "regex 2
end
I know I can do it with if:
if field.match(/head_count_\d{4}_\d{1,2}_\d{1,4}/i)
puts "regex 1"
elsif field.match(/dmi_\d{4}_\d{1,2}_\d{1,4}/i)
puts "regex 2"
end
Just looking for a cleaner solution.
Just remove the match:
field = "head_count_2011_10_75"
case field
when /head_count_\d{4}_\d{1,2}_\d{1,4}/i
puts "regex 1"
when /dmi_\d{4}_\d{1,2}_\d{1,4}/i
puts "regex 2
end
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