I
Ian Macdonald
Hello,
Can anyone explain this to me?
$ echo $LANG
nl_NL
$ irb -f
irb(main):001:0> foo = "préférées"
=> "pr\351f\351r\351es"
irb(main):002:0> foo =~ /[^[:alnum:]]/
=> nil
irb(main):003:0> foo =~ /\W/
=> 2
First question: Why does the final statement return 2 instead of nil?
All characters in foo are alphabetic characters in this locale.
Then:
$ echo $LANG
nl_NL
$ cat ./foo
#!/usr/bin/ruby -w
foo = "préférées"
p foo =~ /[^[:alnum:]]/
p foo =~ /\W/
$ ./foo
2
2
Huh?
Second question: Why does the first regex match now return 2 instead of
nil?
To my way of thinking, both statements should always return nil, whether
or not they are typed into irb or run in a stand-alone script. At the
very least, both statements should return the same answer, regardless of
the context.
What am I missing here?
Ian
--
Ian Macdonald | tachyon emissions overloading the system
(e-mail address removed) |
http://www.caliban.org/ |
|
|
Can anyone explain this to me?
$ echo $LANG
nl_NL
$ irb -f
irb(main):001:0> foo = "préférées"
=> "pr\351f\351r\351es"
irb(main):002:0> foo =~ /[^[:alnum:]]/
=> nil
irb(main):003:0> foo =~ /\W/
=> 2
First question: Why does the final statement return 2 instead of nil?
All characters in foo are alphabetic characters in this locale.
Then:
$ echo $LANG
nl_NL
$ cat ./foo
#!/usr/bin/ruby -w
foo = "préférées"
p foo =~ /[^[:alnum:]]/
p foo =~ /\W/
$ ./foo
2
2
Huh?
Second question: Why does the first regex match now return 2 instead of
nil?
To my way of thinking, both statements should always return nil, whether
or not they are typed into irb or run in a stand-alone script. At the
very least, both statements should return the same answer, regardless of
the context.
What am I missing here?
Ian
--
Ian Macdonald | tachyon emissions overloading the system
(e-mail address removed) |
http://www.caliban.org/ |
|
|