Forum: Ruby on Rails RegEx Question

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.
E13c31390e0369fcd5972292ce0e7b92?d=identicon&s=25 John Nunemaker (Guest)
on 2006-02-10 13:17
(Received via mailing list)
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.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-10 13:38
(Received via mailing list)
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.l...
in it."

HTH
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Mikkel Bruun (Guest)
on 2006-02-10 14:01
(Received via mailing list)
If you are using rails you might want to lookinto auto_link in
ActionView::Helpers::TextHelper


Mikkel Bruun

www.strongside.dk    - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-02-10 14:03
(Received via mailing list)
or you could just use the auto_link helper.

http://rails.rubyonrails.com/classes/ActionView/He...
E13c31390e0369fcd5972292ce0e7b92?d=identicon&s=25 John Nunemaker (Guest)
on 2006-02-10 14:45
(Received via mailing list)
Wow. auto_link is great. I guess I should have dug a little deeper. That
was
really simple. Thanks.
This topic is locked and can not be replied to.