Hi friends,
I have string like
"tes<tr>ubyrails <test@gmail.com>"
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. test@gmail.com
2 tes<tr>ubyrails
"tes<tr>ubyrails <test@gmail.com>".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 = 'tes<tr>ubyrails <test@gmail.com>'
irb(main):002:0> if %r{\A(.*?)\s+(<.*?>)\z} =~ s then front=$1;
rear=$2; p front, rear; end
"tes<tr>ubyrails"
"<test@gmail.com>"
=> ["tes<tr>ubyrails", "<test@gmail.com>"]
Do you have more examples, or is this static data you're using?
That would certainly be helpful.
Kind regards
robert
···
On Fri, Sep 14, 2012 at 10:00 AM, Joel Pearson <lists@ruby-forum.com> wrote:
irb(main):005:0> if %r{\A(.*?)\s+<(.*?)>\z} =~ s then front=$1;
rear=$2; p front, rear; end
"tes<tr>ubyrails"
"test@gmail.com"
=> ["tes<tr>ubyrails", "test@gmail.com"]
Cheers
robert
···
On Fri, Sep 14, 2012 at 10:08 AM, Robert Klemme <shortcutter@googlemail.com> wrote:
On Fri, Sep 14, 2012 at 10:00 AM, Joel Pearson <lists@ruby-forum.com> wrote:
The quick way to do that would be:
"tes<tr>ubyrails <test@gmail.com>".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 = 'tes<tr>ubyrails <test@gmail.com>'
irb(main):002:0> if %r{\A(.*?)\s+(<.*?>)\z} =~ s then front=$1;
rear=$2; p front, rear; end
"tes<tr>ubyrails"
"<test@gmail.com>"
=> ["tes<tr>ubyrails", "<test@gmail.com>"]