From: dblack@... Date: 2002-12-06T10:52:33+09:00 Subject: Re: Regexp imxo - does 'x' work? Hi -- On Fri, 6 Dec 2002, ahoward wrote: > > should this not work ? > > irb(main):001:0> %r{ > irb(main):002:0/ foo > irb(main):003:0/ #foo > irb(main):004:0/ bar > irb(main):005:0/ #bar > irb(main):006:0/ } > /\nfoo\n#foo\nbar\n#bar\n/ That's working, isn't it? > or this? > > irb(main):007:0> %r{foo bar}x > /foo bar/x > > what DOES 'x' do? It's an eXtended regex, which means that literal spaces and newlines are ignored. > perl -e 'print "foobar" =~ /foo bar/x' >> 1 Yikes, I can't even remember what Perl returns for these cases.... > ruby -e 'print "foobar" =~ /foo bar/x' >> 0 The 0 is the index into the string of where the match starts -- and there was indeed a match. Here are some more examples: irb(main):017:0> /foo bar/.match("foobar") nil irb(main):018:0> /foo bar/x.match("foobar") # # Throwing in a newline: irb(main):019:0> /foo irb(main):020:0/ b a r/x.match("foobar") # David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav