Ok, I''m hoping this won''t be a forehead slapper, but take a look at this code: physician.name.sub(/''/, "\\''") I''m trying to substitute a single quote with a backslash and a single quote. This seems pretty simple right? Well, someone kick me and tell me why it''s not :) Here''s what I''m getting if the physician''s name is Test''s User: Tests Users User Huh? Is this normal Ruby behavior (meaning I shoulda sent this to the Ruby group) or is it something funky with the View code? (which is why I sent this here first) Thanks, - Brent
Brent Johnson wrote:> Ok, I''m hoping this won''t be a forehead slapper, but take a look at this > code: > > physician.name.sub(/''/, "\\''") > > I''m trying to substitute a single quote with a backslash and a single > quote. This seems pretty simple right? Well, someone kick me and > tell me why it''s not :) > > Here''s what I''m getting if the physician''s name is Test''s User: > > Tests Users User > > Huh? Is this normal Ruby behavior (meaning I shoulda sent this to the > Ruby group) or is it something funky with the View code? (which is why > I sent this here first) > > Thanks, > > - Brentyou neeed to replace it with "\\\\''" have a look here: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/101824 and in the documentation for sub -- Agnieszka -- Posted via http://www.ruby-forum.com/.
Ahhh, I should have thought to search for "backreference" instead of just backslash. I did look at the API reference for the String object but it didn''t mention the quadruple backslash. Thanks for the info! - Brent On 3/31/06, Agnieszka Figiel <agnieszka.figiel@gmail.com> wrote:> you neeed to replace it with "\\\\''" > > have a look here: > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/101824 > > and in the documentation for sub > > -- > Agnieszka > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >