Hey, New to ruby and unfamiliar with the function ''truncate'' Also, what does this do: gsub(/<.*?>/, '''') Particularly, the regex. Thanks! -- 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-/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 -~----------~----~----~----~------~----~------~--~---
gsub replaces stuff that matches the first expression with the second parameter. In this case, the second parameter is empty, so it''s replacing matches with nothing, effectively stripping them out. The regex looks a little odd to me, but it looks like it''s trying to remove everything between angle-brackets from the string. I''m not sure about the ? though, I would have thought that gsub(/<.*>/,'''') would have the same effect? On Thu, Jul 10, 2008 at 4:15 PM, Justin To <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey, > > New to ruby and unfamiliar with the function ''truncate'' > > Also, what does this do: > > gsub(/<.*?>/, '''') > > Particularly, the regex. > > Thanks! > -- > Posted via http://www.ruby-forum.com/. > > > >-- Paul Smith paul-qDjcQuOzTFkaZ3IpCQCdd7VCufUGDwFn@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I looked further into it. Given the text: <h1>Stuff</h1> The version you posted will first match <h1>, then match </h1>, leaving you with "Stuff". The version I posted is greedy, and matches the whole of <h1>Stuff</h1>, leaving you with nothing. I guess you want the version you posted :) On Thu, Jul 10, 2008 at 4:50 PM, Paul Smith <paulsmithenator-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> gsub replaces stuff that matches the first expression with the second > parameter. In this case, the second parameter is empty, so it''s replacing > matches with nothing, effectively stripping them out. > > The regex looks a little odd to me, but it looks like it''s trying to remove > everything between angle-brackets from the string. I''m not sure about the ? > though, I would have thought that > > gsub(/<.*>/,'''') > > would have the same effect? > > On Thu, Jul 10, 2008 at 4:15 PM, Justin To < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Hey, >> >> New to ruby and unfamiliar with the function ''truncate'' >> >> Also, what does this do: >> >> gsub(/<.*?>/, '''') >> >> Particularly, the regex. >> >> Thanks! >> -- >> Posted via http://www.ruby-forum.com/. >> >> >> >> > > > -- > Paul Smith > paul-qDjcQuOzTFkaZ3IpCQCdd7VCufUGDwFn@public.gmane.org >-- Paul Smith paul-qDjcQuOzTFkaZ3IpCQCdd7VCufUGDwFn@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi -- On Thu, 10 Jul 2008, Justin To wrote:> > Hey, > > New to ruby and unfamiliar with the function ''truncate'' > > Also, what does this do: > > gsub(/<.*?>/, '''') > > Particularly, the regex.gsub does global string substitution of a pattern with a replacement string. You''re absolutely going to have to start using ri if you want to learn about Ruby methods. Start with: ri gsub then realize you care about the String version, and do ri String#gsub and so forth. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ Advancing With Rails August 18-21 Edison, NJ See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---