[ruby-talk:00405] Ruby regular expression incompatibility/bug

From: Julian R Fondren <julian@...>
Date: 1999-06-29 16:46:57 UTC
List: ruby-talk #405
Using ruby 1.3.4-990625 [i586-linux],

Perl:
% perl
$foo = '"'
$foo =~ s/"/x/           # works as expected
print "$foo\n"
--> x

Ruby:
% ruby
foo = '"'
foo =~ s/"/x/
print "#{foo}\n"
--> -:3: undefined local variable or method `s' for #<Object:0x4012ced4>
---> (NameError)

Ruby using irb (clearer):
% ruby -r irb -e1
irb(main):001:0> foo = '"'
"\""
irb(main):002:0> foo =~ s/"/x/
irb(main):003:0"                # what!?
---

So it appears that quotes within regular expressions are treated as
strings rather than characters to match in the regular experssions.
What is worse:

irb(main):005:0> foo =~ s/\"/x/
irb(main):006:0"

quotes can't be used at all! Also, so that it is even more clear that this
is a ruby problem and not an irb problem:

% ruby
foo = '"'
foo =~ s/\"/x/
-:2: parse error
foo =~ s/\"/x/
          ^
Thank you,

In This Thread