From: Simon Strandgaard Date: 2004-09-20T19:08:35+09:00 Subject: Re: Ruby nuby -- modifying Regexp casefold On Monday 20 September 2004 10:59, Luca Pireddu wrote: > Hi all. I have just started playing with Ruby and I'm stuck on something. > Is there some trick to modify the casefold attribute of a Regexp object > after it's been instantiated? when Regexp has been instantiated, then you cannot modify it. There is no way to modify a regexp instance. > The best idea I've had is the following: > irb(main):001:0> a = Regexp.new('a') > => /a/ > irb(main):002:0> aA = Regexp.new(a.to_s, Regexp::IGNORECASE) > => /(?-mix:a)/i (?-i) turns off ignorcase mode.. > But it doesn't seem to work: > irb(main):003:0> a =~ 'a' > => 0 > irb(main):004:0> a =~ 'A' > => nil > irb(main):005:0> aA =~ 'a' > => 0 > irb(main):006:0> aA =~ 'A' > => nil maybe try this if you want line 006 to return an index aA=Regexp.new('(?i)'+a.source) > Something I don't understand is happening here. Where did the 'i' go on > line 14? > irb(main):013:0> aA = Regexp.new(a.to_s, Regexp::IGNORECASE) > => /(?-mix:a)/i ruby 1.8.1 outputs => /(?i-mx:a)/ something must have been changed with 1.8.2 the output on line 14 is wrong. > irb(main):014:0> aA.to_s > => "(?-mix:a)" > irb(main):015:0> > > I'm using Ruby 1.8.2 (2004-08-24) [i386-linux], irb 0.9(02/07/03) on > Debian. -- Simon Strandgaard