From: Rob Biedenharn Date: 2007-02-14T10:25:10+09:00 Subject: Re: Puzzling regex behaviour On Feb 13, 2007, at 7:13 PM, Ian Macdonald wrote: > On Wed 14 Feb 2007 at 09:08:17 +0900, David Balmain wrote: > >> On 2/14/07, Ian Macdonald wrote: >>> >>> I should have asked by now, but can anyone else reproduce this with >>> Ruby 1.8.5? >> >> I can reproduce this 1.8.4 > > Just to be clear, you are confirming that the following code: > > foo = "pr�f�r�es" > p foo =~ /[^[:alnum:]]/ > > prints nil in irb and 2 in a stand-alone script when in both cases > your > locale is preset to nl_NL? > > Ian > -- > Ian Macdonald | On a clear disk you can seek forever. > ian@caliban.org | > http://www.caliban.org/ | I'm beginning to wonder if the original question is even accurate. Doing nothing more than changing the encoding and re-saving the file (where the value for foo was a cut-n-paste from the email), there doesn't seem to be any discrpeancy between ruby and irb. (This output is from ruby 1.8.5, but 1.8.2 was the same) rab:code/ruby $ file regexp_and_alnum_versus_w.rb regexp_and_alnum_versus_w.rb: ISO-8859 text rab:code/ruby $ cat regexp_and_alnum_versus_w.rb foo = "pr?f?r?es" alnum = /[^[:alnum:]]/ dubya = /\W/ puts "foo\n => #{foo.inspect}" [ alnum, dubya ].each do |re| puts "foo =~ #{re}\n => #{foo =~ re}" end rab:code/ruby $ ruby regexp_and_alnum_versus_w.rb foo => "pr\351f\351r\351es" foo =~ (?-mix:[^[:alnum:]]) => 2 foo =~ (?-mix:\W) => 2 rab:code/ruby $ irb -r regexp_and_alnum_versus_w.rb foo => "pr\351f\351r\351es" foo =~ (?-mix:[^[:alnum:]]) => 2 foo =~ (?-mix:\W) => 2 >> eixt NameError: undefined local variable or method `eixt' for main:Object from (irb):1 >> exit rab:code/ruby $ file regexp_and_alnum_versus_w.rbregexp_and_alnum_versus_w.rb: UTF-8 Unicode text rab:code/ruby $ cat regexp_and_alnum_versus_w.rb foo = "pr�f�r�es" alnum = /[^[:alnum:]]/ dubya = /\W/ puts "foo\n => #{foo.inspect}" [ alnum, dubya ].each do |re| puts "foo =~ #{re}\n => #{foo =~ re}" end rab:code/ruby $ ruby regexp_and_alnum_versus_w.rb foo => "pr\303\251f\303\251r\303\251es" foo =~ (?-mix:[^[:alnum:]]) => 2 foo =~ (?-mix:\W) => 2 rab:code/ruby $ irb -r regexp_and_alnum_versus_w.rb foo => "pr\303\251f\303\251r\303\251es" foo =~ (?-mix:[^[:alnum:]]) => 2 foo =~ (?-mix:\W) => 2 >> exit -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com