From: Warren Brown Date: 2004-09-21T01:01:00+09:00 Subject: Re: Ruby nuby -- modifying Regexp casefold Luca, > Is there some trick to modify the casefold attribute of a Regexp > object after it's been instantiated? No, Regexps are immutable - you can't change them. However, your idea of creating a new object based on the old one is sound. > 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 The problem here is that you are using Regexp#to_s instead of Regexp#source. Regexp#to_s tries to give you all of the information about the regular expression, including the three flags m, I, and x. What you want is the actual source of the regular expression so you can modify the flags. irb(main):002:0> a.to_s => "(?-mix:a)" irb(main):003:0> a.source => "a" > But it doesn't seem to work: > irb(main):006:0> aA =~ 'A' > => nil Since you used a.to_s, aA is the regular expression /(?-mix:a)/i, but the "(?-mix:a)" portion of the regular expression is overriding the i flag, so it is not having any effect. I hope this helps. - Warren Brown