Skip to content

Instantly share code, notes, and snippets.

@searls
Created June 18, 2011 14:35
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save searls/1033143 to your computer and use it in GitHub Desktop.
Save searls/1033143 to your computer and use it in GitHub Desktop.
JavaScript example of Gruber's URL matching regex http://daringfireball.net/2010/07/improved_regex_for_matching_urls
//Gruber wrote this regex for matching URLs, but it took a small amount of massage to use it in JavaScript. So here.
//Sauce: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
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 www.twitter.com yay') //winning.
@RalphRezendeLarsen
Copy link

Unfortunately it doesn't accept "pinterest.com/p" as an url

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