I’m trying to understand why the following returns false: (** I should have put “outputs 0” **)
puts "a\nb" =~ Regexp.new(Regexp.escape("a\nb"), Regexp::MULTILINE | Regexp::EXTENDED)
Perhaps someone could explain.
I am trying to generate a Regexp from a multi-line String that will match the String.
Thanks in advance
putswill always returnnil.Your code should work fine, albeit lengthy.
=~returns the position of the match which is 0.You could also use:
or
Note: The
moption isn’t necessary in this example but demonstrates how it would be used withoutRegexp.new.