1

What is the regular expression SO/SE sites use for making the hyperlink active?

There is a problem if the hyperlink is in the sentence, that it might be followed by interpunction. I see that if there is a dot or parenthesis at the end of hyperlink, it is not considered its part. So is it something like this?

preg_replace('/(https?:\/\/\S+[^),.?!])/', '<a href="\1">\1</a>', $s);

But I've seen a link which ended by . (dot), so this would break it. It seems this will never work 100% (it can't), but I'm wondering what would be the optimal as-tweaked-as-possible solution.

5
/(^|\s)(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\]])($|\W)/gi

http://code.google.com/p/pagedown/source/browse/Markdown.Converter.js#1205

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .