From: Robert Klemme Date: 2012-10-17T23:24:29+09:00 Subject: Re: Drop 1st and last particular character On Wed, Oct 17, 2012 at 1:58 PM, Joel Pearson wrote: >> irb(main):010:0> s.gsub /\A#|#\z/, '' >> => "aaaa\n#bbb#cc#\n" >> irb(main):011:0> s == s.gsub(/\A#|#\z/, '') >> => true > This looks like the best solution. One should use gsub! though if the old String does not need to be retained - that saves memory because the String is changed in place. If the old String should be retained this approach might actually be more efficient since AFAIK both strings share the char buffer if I am not mistaken: s = s[/^#?(.*?)#?\z/, 1] But this is micro optimizing already so better pick what suits you best. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/