Create a gist now

Instantly share code, notes, and snippets.

JavaScript example of Gruber's URL matching regex
//Gruber wrote this regex for matching URLs, but it took a small amount of massage to use it in JavaScript. So here.
var p = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
p.exec('party fun yay') //winning.

Unfortunately it doesn't accept "" as an url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment