Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to automatically hyperlink url's from some plain text and I have a simple (but not perfect) regular expression that does this.
However when I try and use it with a url that wraps onto a new line, the url itself contains a new line and stops the browser going to the right page.
Allow me to demonstrate with this bit of code:
If file.txt has the following:#!/usr/bin/perl use strict; my $output = ""; open(FILE, "file.txt") || die "$!"; while(<FILE>) { $output .= $_; } close FILE; $output =~ s#(http://[^\!\"\£\$\^\*\(\)\{\}\[\]\;\:\'\@\,\<\> ]+)#\<a +href="$1" target="_blank"\>$1\</a\>#gis; print $output;
then my output is:The quick brown fox at http://fish.org would like to go home and http: +//see through.com/pants/foo/bar what there is to eat
So my question is, is there any way i can remove that \n that is in the middle of the a href?The quick brown fox at <a href="http://fish.org" target="_blank">http: +//fish.org</a> would like to go home and <a href="http://see through.com" target="_blank">http://see through.com</a> what there is to eat
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automatically hyperlinking text fails with newlines
by suaveant (Parson) on Sep 20, 2001 at 21:05 UTC | |
by Anonymous Monk on Sep 20, 2001 at 21:14 UTC | |
by suaveant (Parson) on Sep 20, 2001 at 21:33 UTC | |
by alien_life_form (Pilgrim) on Sep 21, 2001 at 12:04 UTC | |
|
Re: Automatically hyperlinking text fails with newlines
by alien_life_form (Pilgrim) on Sep 20, 2001 at 21:20 UTC |