From: Pistos Christou Date: 2006-03-30T00:44:50+09:00 Subject: Re: Regexp gotcha James H. wrote: > Are you asking why we can write > > if match_result > > as equivalent to > > if match_result != nil and match_result != false > > ? No, not at all. :) I'm just whining a bit that =~ can return both nil and false. It's not that big a deal, but this is something that could catch unaware people who would follow down the same tracks as I did and assume match_result != nil would cover all the bases, when it doesn't. Robert Klemme wrote: > Personally I prefer to use /rx/ =~ str over str =~ /rx/ - to me this > makes it clearer that the RX is the one that does the matching. Just > personal taste maybe but I think I also remember that that variant is a > tad faster. I didn't even realize this could be done :) (though I see now that it is documented, =~ being a synonym for Regexp#match). If I lived in a vacuum for the last 15 years, and Ruby was the first and only programming language I ever learned, then I would have done it that way, too, from the very start. :) Alas, I came from [other languages and then] Perl, so it was just a carry over to continue using str =~ /regexp/. FWIW, we still have the same problem: irb(main):255:0> r1 =~ s => 0 irb(main):256:0> r2 =~ s => nil irb(main):257:0> r3 =~ s => false I've taken note that you say that r =~ s is faster. I (or someone else) will have to do some benchmarking to see whether that's really true, and how much speed gain can be had. Diakonos suffers when you use large and many regexps for syntax highlighting, so I'd be interested in anything that can speed that up. Pistos -- Posted via http://www.ruby-forum.com/.