[#4766] Wiki — "Glen Stampoultzis" <trinexus@...>

21 messages 2000/09/04
[#4768] RE: Wiki — "NAKAMURA, Hiroshi" <nahi@...> 2000/09/04

Hi, Glen,

[#4783] Re: Wiki — Masatoshi SEKI <m_seki@...> 2000/09/04

[#4785] Re: Wiki — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/09/05

Howdy,

[#4883] Re-binding a block — Dave Thomas <Dave@...>

16 messages 2000/09/12

[#4930] Perl 6 rumblings -- RFC 225 (v1) Data: Superpositions — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/09/15

[#4936] Ruby Book Eng. translation editor's questions — Jon Babcock <jon@...>

20 messages 2000/09/16

[#5045] Proposal: Add constants to Math — Robert Feldt <feldt@...>

15 messages 2000/09/21

[#5077] Crazy idea? infix method calls — hal9000@...

This is a generalization of the "in" operator idea which I

17 messages 2000/09/22

[#5157] Compile Problem with 1.6.1 — Scott Billings <aerogems@...>

When I try to compile Ruby 1.6.1, I get the following error:

15 messages 2000/09/27

[ruby-talk:4747] Re: Possible regex bug?

From: ts <decoux@...>
Date: 2000-09-02 13:46:07 UTC
List: ruby-talk #4747
>>>>> "D" == Dave Thomas <Dave@thomases.com> writes:

D> So, in this respect, Perl and Ruby do the same thing.

 There is a difference between perl and ruby.

 If you look at simple example you'll probably not see it, for example :

pigeon% cat b.rb
#!/usr/bin/ruby
'foo'.scan(/o?/) do
   p "match <#$&>"
end
pigeon% b.rb
"match <>"
"match <o>"
"match <o>"
"match <>"
pigeon% 

pigeon% cat a.pl
#!/usr/bin/perl -l
print "match <$&>" while 'foo' =~ /o?/g;
pigeon% 

pigeon% a.pl
match <>
match <o>
match <o>
match <>
pigeon%

 But when you write regexp with non-greedyness you see the difference :

pigeon% cat b.rb
#!/usr/bin/ruby
'foo'.scan(/o??/) do
   p "match <#$&>"
end
p 'bar'.gsub(/\w??/) do |x|
   "<#{x}>"
end
pigeon% 

pigeon% b.rb
"match <>"
"match <>"
"match <>"
"match <>"
"<>b<>a<>r<>"
pigeon% 

pigeon% cat a.pl
#!/usr/bin/perl -l
print "match <$&>" while 'foo' =~ /o??/g;
$_ = 'bar';
s/\w??/<$&>/g;
print;
pigeon% a.pl
match <>
match <>
match <o>
match <>
match <o>
match <>
<><b><><a><><r><>
pigeon% 

 The difference seems because perl has complex rule to resolve zero-length
 match (a zero-length match don't move the "cursor").

 For ruby an expression like /\w??/ in global context is more like :
   1) try the next expression in the regexp (in this case return with an
      empty match)
   2) move the "cursor"
   3) go to 1

p.s.: the examples are extract from perlre


Guy Decoux

In This Thread