or you could just use the auto_link helper.
http://rails.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000426
On 2/10/06, Alex Young <alex@blackkettle.org>
wrote:>
> John Nunemaker wrote:
> > Hi,
> > This is more of a Ruby question than Rails. I want to autolink
url''s in
> a given
> > string. I''m not great with regular expressions and I wandered
if anybody
> has an
> > example. Thanks.
> >
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> irb(main):010:0> string = ''This is a string with a
> http://test.link/foo.bar?query=&bar in it.''
> => "This is a string with a http://test.link/foo.bar?query=&bar
in it."
>
> irb(main):011:0> string.gsub(%r{(http://\S+)}, "<a
> href=''#{$1}''>#{$1}</a>")
> => "This is a string with a <a
href=''http://test.link/foo.bar?query=&bar''>
> http://test.link/foo.bar?query=&bar</a> in it."
>
> HTH
> --
> Alex
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060210/b1899bb5/attachment.html