RegEx Question


#1

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.


#2

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
removed_email_address@domain.invalid
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


#3

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)


#4

Wow. auto_link is great. I guess I should have dug a little deeper. That
was
really simple. Thanks.


#5

or you could just use the auto_link helper.

http://rails.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000426