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.
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
[email protected]
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+)}, “#{$1}”)
=> “This is a string with a http://test.link/foo.bar?query=&bar
in it.”
HTH
If you are using rails you might want to lookinto auto_link in
ActionView::Helpers::TextHelper
Mikkel B.
www.strongside.dk - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk - Buy Old Stuff!(DK)
Wow. auto_link is great. I guess I should have dug a little deeper. That
was
really simple. Thanks.
or you could just use the auto_link helper.
http://rails.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000426