I’m using Ruby to do a simple substring type match. I’m trying to understand why the following happens:
irb(main):024:0> puts "match" if "foo" =~ /foo/
match
=> nil
irb(main):025:0> puts "match" if "foo" =~ /foo,/
=> nil
how can this regex be modified so that if any part of the search criteria matches “foo”, a match is made?
You’ve got your comparisons backwards:
The
=~operator is a bit of history that has fallen out of style because it’s not self-explanatory.