in reply to Re: regex to identify http:// in html
in thread regex to identify http:// in html
Your use of a non-greedy quantifier isn't best here. You are already specifying \S and, since you are being specific, the non-greediness isn't really buying you anything. (In fact, it's somewhat less efficient.) You can also skip the capturing of space at the end. You are just re-adding it anyway, so just leave it alone to begin with. Your regex would be better written as:
And, you might as well catch https as well:s!(http://\S+)!<a href="$1">$1</a>!g;
s!(https?://\S+)!<a href="$1">$1</a>!g;
-sauoq "My two cents aren't worth a dime.";
|
|---|