From: Robert Klemme Date: 2012-10-16T16:50:36+09:00 Subject: Re: Drop 1st and last particular character On Tue, Oct 16, 2012 at 9:38 AM, Hans Mackowiak wrote: > or both regexp combined: > "#hit#here#".gsub(/(^#)|(\#$)/,'') #=> "hit#here" We can also combine by positively matching: irb(main):001:0> s = "#hit#here#" => "#hit#here#" irb(main):002:0> s = s[/^#?(.*?)#?\z/, 1] => "hit#here" All possible combinations irb(main):003:0> %w{hi#there #hi#there hi#there# #hi#there#}.each {|s| p s[/^#?(.*?)#?\z/, 1]} "hi#there" "hi#there" "hi#there" "hi#there" => ["hi#there", "#hi#there", "hi#there#", "#hi#there#"] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/