in reply to replace url in text with html link

A very simple HTML link replacement regex that ignores the last period (.):

my $html = do { local $/; <DATA> }; $html =~ s!(https*:\S*?)(\.*?\s)!<a href="$1">$1</a>$2!gm; print $html; __DATA__ Students can activate their UMSIS userids on-line by filling out and s +ubmitting the form at https://umsis.miami.edu/sign-up. ...which can be obtained via the web at http://www.miami.edu/it-forms/ +.


Replies are listed 'Best First'.
Re^2: replace url in text with html link
by davidrw (Prior) on May 24, 2005 at 16:27 UTC
    This might be nitpicky, but perhaps (hopefully) educational for the OP. Caught my eye because we actually had almost identical responses... (mine is here)
    • I had http? and you had https* -- yours would match httpssss://blah.com since the * is zero more instead of ? being 0 or 1
    • I have ://\S+? and you have :\S*? -- yours would match http:. or http: or http:/blah or http:blah.com
    • I have (\.?\s) and you have (\.*?\s) -- I think yours is better here, but i'm sure how the two non-greedy (one for \S and one for \.) work together in the case of http://blah.com...