Regexp imxo - does 'x' work?

.. and it returns 'nil' for no match?

···

> perl -e 'print "foobar" =~ /foo bar/x' >> 1
> ruby -e 'print "foobar" =~ /foo bar/x' >> 0

Perl is returning whether there was a match (undef if no match).
Ruby is returning the offset of the match (strings start at 0).

  • Iain wrote:

perl -e ‘print “foobar” =~ /foo bar/x’ >> 1
ruby -e ‘print “foobar” =~ /foo bar/x’ >> 0

Perl is returning whether there was a match (undef if no match).
Ruby is returning the offset of the match (strings start at 0).

… and it returns ‘nil’ for no match?

Correct. The ruby equivalent of undef =)

ruby -e ‘print “foobar” =~ /fred/’
perl -e ‘print “foobar” =~ /fred/’

cheers,

···


Iain.

perl -e ‘print “foobar” =~ /foo bar/x’ >> 1
ruby -e ‘print “foobar” =~ /foo bar/x’ >> 0

Perl is returning whether there was a match (undef if no match).
Ruby is returning the offset of the match (strings start at 0).

… and it returns ‘nil’ for no match?

Try ‘irb’ and/or ‘ri’.

Gavin

···

From: “Ted” ted@datacomm.com