Using a regular expression, how would I match "howdy" in the following? "begin howdy end begin hello end" =~ /begin (.*) end/ match = $1 # current value of match = "howdy end begin hello" A handy regex tool: http://www.rubular.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 14, 2008, at 9:29 PM, gsterndale wrote:> > Using a regular expression, how would I match "howdy" in the > following? > > "begin howdy end begin hello end" =~ /begin (.*) end/ > > match = $1 > > # current value of match = "howdy end begin hello"Assuming it''s that exact string... >> "begin howdy end begin hello end" =~ /begin (.*?) /; $1 => "howdy" But I suspect that won''t work for your real usage... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''re right. Unfortunately, that won''t work for me. However, the following will! >> "begin hi there end begin hello end" =~ /begin (.*?) end/; $1 => "hi there" Thanks Philip On Jul 15, 1:35 am, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Jul 14, 2008, at 9:29 PM, gsterndale wrote: > > > > > Using a regular expression, how would I match "howdy" in the > > following? > > > "begin howdy end begin hello end" =~ /begin (.*) end/ > > > match = $1 > > > # current value of match = "howdy end begin hello" > > Assuming it''s that exact string... > > >> "begin howdy end begin hello end" =~ /begin (.*?) /; $1 > => "howdy" > > But I suspect that won''t work for your real usage...--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---