Forum: Ruby on Rails help replacing all @user patterns with link (regular expressions)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
dino d. (Guest)
on 2009-04-06 21:02
(Received via mailing list)
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
Frederick C. (Guest)
on 2009-04-06 21:22
(Received via mailing list)
On 6 Apr 2009, at 17:53, dino d. wrote:

> 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
This topic is locked and can not be replied to.