Want to get string between specialchars at endof the string

Hi friends,
I have string like
“tesubyrails [email protected]
From the above string i always should get the text between chars <>
from the string .I should get chars should be between chars which are
in endof string only
I want result should be as 2 strings

  1. [email protected]
    2 tesubyrails

The quick way to do that would be:

“tesubyrails [email protected]”.split(" <").each do |el| puts
el[0…-2] end

If you wanted something a bit more flexible I recommend regex. Do you
have more examples, or is this static data you’re using?

On Fri, Sep 14, 2012 at 10:08 AM, Robert K.
[email protected] wrote:

irb(main):001:0> s = ‘tesubyrails [email protected]
irb(main):002:0> if %r{\A(.?)\s+(<.?>)\z} =~ s then front=$1;
rear=$2; p front, rear; end
“tesubyrails”
[email protected]
=> [“tesubyrails”, “[email protected]”]

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”
[email protected]
=> [“tesubyrails”, “[email protected]”]

Cheers

robert

On Fri, Sep 14, 2012 at 10:00 AM, Joel P. [email protected]
wrote:

The quick way to do that would be:

“tesubyrails [email protected]”.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 [email protected]
irb(main):002:0> if %r{\A(.?)\s+(<.?>)\z} =~ s then front=$1;
rear=$2; p front, rear; end
“tesubyrails”
[email protected]
=> [“tesubyrails”, “[email protected]”]

Do you have more examples, or is this static data you’re using?

That would certainly be helpful.

Kind regards

robert

str = “tesubyrails [email protected]

name, email = str.split
email = email[1…-2]

puts name, email

–output:–
tesubyrails
[email protected]