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 > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/railsirb(main):010:0> string = ''This is a string with a test.link/foo.bar?query=&bar in it.'' => "This is a string with a 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=''test.link/foo.bar?query=&bar''>test.link/foo.bar?query=&bar</a> in it." HTH -- Alex
If you are using rails you might want to lookinto auto_link in ActionView::Helpers::TextHelper Mikkel Bruun strongside.dk - Football Portal(DK) nflfeed.helenius.org - Football News(DK) ting.minline.dk - Buy Old Stuff!(DK) -- Posted with DevLists.com. Sign up and save your time!
or you could just use the auto_link helper. 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 > > lists.rubyonrails.org/mailman/listinfo/rails > irb(main):010:0> string = ''This is a string with a > test.link/foo.bar?query=&bar in it.'' > => "This is a string with a 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=''test.link/foo.bar?query=&bar''> > test.link/foo.bar?query=&bar</a> in it." > > HTH > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: wrath.rubyonrails.org/pipermail/rails/attachments/20060210/b1899bb5/attachment.html