in reply to Re: Automatically hyperlinking text fails with newlines
in thread Automatically hyperlinking text fails with newlines

Hi, thanks for this.

However I only want to remove the \n from inside the hyperlink whilst still preserving the newlines elsewhere. In other words the output should be:

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://seethrough.c +om" target="_blank">http://see through.com</a> what there is to eat
(http://www.seethrough.com is preserved within the href tag, but still has the newline for the display)

Replies are listed 'Best First'.
Re: Re: Re: Automatically hyperlinking text fails with newlines
by suaveant (Parson) on Sep 20, 2001 at 21:33 UTC
    well then... you could pass $1 as a function, since you are matching the hyperlink with the \n, similar to...
    s/regex/make_link($1)/eg; sub make_link { my $url = $_[0]; $url =~ s/\s+//g; qq`<A HREF="$url">$url</A>`; }

                    - Ant
                    - Some of my best work - Fish Dinner

Re: Re: Re: Automatically hyperlinking text fails with newlines
by alien_life_form (Pilgrim) on Sep 21, 2001 at 12:04 UTC
    Greetings.

    This being the case, I would (still) slurp the entire file, not replace \n, and put \n among the acceptable characters in the regexp (and I *think* you may have to use the /s modifier). I would then replace the \n still embedded in the href.

    Not perfect, because this:

    Ehi, check this out on http://cnn.com\n
    dude!
    
    would yield: http://cnn.comdude. In other words, if you want ignorable newlines within URIs, then URIS must always be separated by real whitespace from the surrounding text.

    Cheers,
    alf