[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regular Expresion Error?

Filipe

9/29/2007 10:21:00 PM

Hello all,

According to the Regular Expressions section of the following ruby
guide: http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_std...,
the piece of code bellow should have returned "He<<ll>>o", instead of
"No match". Has anyone got an idea on why it isn't working?

Notice that if I tell the interpreter how big \w should be in an
explicit way by adding {1,1}, the expected result is given.

def showRE(a,re)
#re = Regexp.new(re) if re.class==String
#re=Regexp.new(re.to_s) if re.class==Integer
if a=~re
"#{$`}<<#{$&}>>#{$'}"
else
"no match"
end
end

puts showRE("Hello", /(\w)\1/) #=> no match
puts showRE("Hello", /(\w{1,1})\1/) #=> He<<ll>>o

Thanks in advance for helping

4 Answers

Filipe

9/29/2007 10:27:00 PM

0

Forgot to mention: Im running ruby 1.8.6 at Mac OS X 10.4.

Sebastian Hungerecker

9/30/2007 8:46:00 AM

0

Filipe wrote:
> def showRE(a,re)
> #re = Regexp.new(re) if re.class==String
> #re=Regexp.new(re.to_s) if re.class==Integer
> if a=~re
> "#{$`}<<#{$&}>>#{$'}"
> else
> "no match"
> end
> end
>
> puts showRE("Hello", /(\w)\1/) #=> no match
> puts showRE("Hello", /(\w{1,1})\1/) #=> He<<ll>>o

Both return "He<<ll>>o" for me.
ruby 1.8.6 (2007-09-23 patchlevel 110) [x86_64-linux]


--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Wolfgang Nádasi-donner

9/30/2007 8:52:00 AM

0

Filipe wrote:
> puts showRE("Hello", /(\w)\1/) #=> no match
> puts showRE("Hello", /(\w{1,1})\1/) #=> He<<ll>>o

Both return "He<<ll>>o" on my machine too (Windows2000 -
OneClickInstaller 186-25).

Wolfgang Nádasi-Donner
--
Posted via http://www.ruby-....

Filipe

10/5/2007 1:26:00 AM

0

On Sep 30, 5:52 am, "Wolfgang N?dasi-Donner" <ed.oda...@wonado.de>
wrote:
> Filipe wrote:
> > puts showRE("Hello", /(\w)\1/) #=> no match
> > puts showRE("Hello", /(\w{1,1})\1/) #=> He<<ll>>o
>
> Both return "He<<ll>>o" on my machine too (Windows2000 -
> OneClickInstaller 186-25).
>
> Wolfgang N?dasi-Donner
> --
> Posted viahttp://www.ruby-....

looks like the ruby interpreter I was running was jruby, under
netbeans. Unfourtunately, I didn't realize it at first.