dino d.
2009-Apr-06 16:53 UTC
help replacing all @user patterns with link (regular expressions)
Hi - I want to add a feature to my comment forum where anytime someone types in @username, I can grab the username, make sure it''s valid, and if so, replace it with a link to that user''s profile. So, I think I want something like: comment = comment.gsub("/@[A-Za-z0-9]*/", ?) How do I grab the tailing string (after dropping the @) in this regular expression, and how do I create a link string in the controller (link_to?) ? Thanks for any help, Dino --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Apr-06 17:21 UTC
Re: help replacing all @user patterns with link (regular expressions)
On 6 Apr 2009, at 17:53, dino d. wrote:> > Hi - I want to add a feature to my comment forum where anytime someone > types in @username, I can grab the username, make sure it''s valid, and > if so, replace it with a link to that user''s profile. So, I think I > want something like: > > > comment = comment.gsub("/@[A-Za-z0-9]*/", ?) > > How do I grab the tailing string (after dropping the @) in this > regular expression, and how do I create a link string in the > controller (link_to?) ? >Probably easiest to use the block form of gsub - your block gets called for each match, your block should return the replacement text. Fred> Thanks for any help, > Dino > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---