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!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |