marți, 15 noiembrie 2011

Javascript URL regex

Here's how i check and replace URL patterns in Javascript, with this neat URL regexp pattern:


var URL3_pat = /http:\/\/([\w\d\.\-]+)\.([a-z]{2,8})(($)|([\/\?\#]+$)|(([\/\?\#]+[\w\d\:\@\%\/\;\~\_\?\\\+\-\=\\\\\.\&\,]+)))/m;

r = t.replace(URL3_pat, '<a href="$&" target="out">$&</a>');


Huh? what do you think about this regular expression?

Niciun comentariu:

Trimiteți un comentariu