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.
John Nunemaker (Guest)
on 2006-02-10 14: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.
Alex Y. (Guest)
on 2006-02-10 14: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
> 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+)}, "<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
Mikkel B. (Guest)
on 2006-02-10 15:01
(Received via mailing list)
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)
Chris H. (Guest)
on 2006-02-10 15:03
(Received via mailing list)
or you could just use the auto_link helper.

http://rails.rubyonrails.com/classes/ActionView/He...
John Nunemaker (Guest)
on 2006-02-10 15: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.