From: Ian Macdonald Date: 2007-02-16T18:30:46+09:00 Subject: Re: Puzzling regex behaviour On Fri 16 Feb 2007 at 00:40:08 +0900, Robert Klemme wrote: > On 15.02.2007 16:19, Ian Macdonald wrote: > > >Look at this: > > > >$ irb > >irb(main):001:0> foo = "pr�f�r�es" > >=> "pr\351f\351r\351es" > >irb(main):002:0> foo =~ /[^[:alnum:]]/ > >=> nil > > > >$ irb --noreadline > >irb(main):001:0> foo = "pr�f�r�es" > >=> "pr\351f\351r\351es" > >irb(main):002:0> foo =~ /[^[:alnum:]]/ > >=> 2 > > > >This is _very_ unexpected and undesirable behaviour and, as such, > >probably qualifies as a bug. > > Yeah, seems so. Unless it's documented behavior. :-) > > >Interestingly, adding "require 'readline'" to the stand-alone script > >does _not_ introduce this behaviour, so it must be something to do with > >the initialisation that irb does. > > It's really strange as both print the same output. You mean that both of them show foo to contain the same string of bytes? > How about doing this > - just to be sure that both strings contain the same sequence of bytes: > > require 'enumerator' > foo.to_enum(:each_byte).to_a.join(", ") In both cases: => "112, 114, 233, 102, 233, 114, 233, 101, 115" Somehow, it is the regex that is being handled differently, not the string. Ian -- Ian Macdonald | Reality does not exist -- yet. ian@caliban.org | http://www.caliban.org/ | | |