From: Robert Klemme Date: 2012-09-14T17:08:59+09:00 Subject: Re: want to get string between specialchars at endof the string On Fri, Sep 14, 2012 at 10:08 AM, Robert Klemme wrote: > On Fri, Sep 14, 2012 at 10:00 AM, Joel Pearson wrote: >> The quick way to do that would be: >> >> "tesubyrails ".split(" <").each do |el| puts >> el[0..-2] end >> >> If you wanted something a bit more flexible I recommend regex. > > Like > > irb(main):001:0> s = 'tesubyrails ' > irb(main):002:0> if %r{\A(.*?)\s+(<.*?>)\z} =~ s then front=$1; > rear=$2; p front, rear; end > "tesubyrails" > "" > => ["tesubyrails", ""] Oops, he wanted the text between <>: irb(main):005:0> if %r{\A(.*?)\s+<(.*?)>\z} =~ s then front=$1; rear=$2; p front, rear; end "tesubyrails" "test@gmail.com" => ["tesubyrails", "test@gmail.com"] Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/