var text="Afganistan (+86)" var code=text.sub(/\w+/, '''') result: code = (+86) ------------------------------ var text = "Antigua and Barbuda (+1268)" var code=text.sub(/\w+/, '''') result : code = and Barbuda (+1268)" -------------------------------------- what regular expression I can try to get second one as first. ie (+1268) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
HUNT HUNT wrote:> var text="Afganistan (+86)" > var code=text.sub(/\w+/, '''') > result: code = (+86) > ------------------------------ > > var text = "Antigua and Barbuda (+1268)" > var code=text.sub(/\w+/, '''') > result : code = and Barbuda (+1268)" > > -------------------------------------- > what regular expression I can try to get second one as first. ie (+1268)Do you want "(+1268)" from the second query? If so, does var code=text.sub(/[\w+ ]/, '''') work? See http://rubular.com/r/g5I6tYxb5C for where I show it works. Thanks, ben -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
"Antigua and Barbuda (+1268)".scan(/\d+/).to_s => 1268 "Antigua and Barbuda (+1268)".scan(/\(\+\d+\)/).to_s => (+1268) On Tue, Apr 27, 2010 at 4:47 PM, HUNT HUNT <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> var text="Afganistan (+86)" > var code=text.sub(/\w+/, '''') > result: code = (+86) > ------------------------------ > > var text = "Antigua and Barbuda (+1268)" > var code=text.sub(/\w+/, '''') > result : code = and Barbuda (+1268)" > > -------------------------------------- > what regular expression I can try to get second one as first. ie (+1268) > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi -- On Tue, 27 Apr 2010, Vladimir Rybas wrote:> "Antigua and Barbuda (+1268)".scan(/\d+/).to_s > => 1268 > > "Antigua and Barbuda (+1268)".scan(/\(\+\d+\)/).to_s > => (+1268)There''s a nice technique for quickly getting a substring from a string using a subscript-style notation: "Antigua and Barbuda (+1268)"[/\(\+\d+\)/] # "(+1268)" David -- David A. Black, Senior Developer, Cyrus Innovation Inc. THE Ruby training with Black/Brown/McAnally COMPLEAT Coming to Chicago area, June 18-19, 2010! RUBYIST http://www.compleatrubyist.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
nice one David! On Tue, Apr 27, 2010 at 5:34 PM, David A. Black <dblack-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > On Tue, 27 Apr 2010, Vladimir Rybas wrote: > > "Antigua and Barbuda (+1268)".scan(/\d+/).to_s >> => 1268 >> >> "Antigua and Barbuda (+1268)".scan(/\(\+\d+\)/).to_s >> => (+1268) >> > > There''s a nice technique for quickly getting a substring from a > string using a subscript-style notation: > > "Antigua and Barbuda (+1268)"[/\(\+\d+\)/] # "(+1268)" > > > David > > -- > David A. Black, Senior Developer, Cyrus Innovation Inc. > > THE Ruby training with Black/Brown/McAnally > COMPLEAT Coming to Chicago area, June 18-19, 2010! > RUBYIST http://www.compleatrubyist.com > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Vladimir Rybas wrote:> nice one David!I did with this var code=text.sub(/[a-z A-Z]/, '''') -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David A. Black wrote:> Hi -- > On Tue, 27 Apr 2010, Vladimir Rybas wrote: > >> "Antigua and Barbuda (+1268)".scan(/\d+/).to_s >> => 1268 >> >> "Antigua and Barbuda (+1268)".scan(/\(\+\d+\)/).to_s >> => (+1268) > > There''s a nice technique for quickly getting a substring from a > string using a subscript-style notation: > > "Antigua and Barbuda (+1268)"[/\(\+\d+\)/] # "(+1268)"Ooh, nice! Didn''t know about that.> > > DavidBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.