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
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]”]
“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?