Skip to content

Instantly share code, notes, and snippets.

@johnmcdowall
Created July 16, 2011 17:33
Show Gist options
  • Save johnmcdowall/1086574 to your computer and use it in GitHub Desktop.
Save johnmcdowall/1086574 to your computer and use it in GitHub Desktop.
Gruber's Ultimate URL RegExp for Ruby
/(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i
See http://daringfireball.net/2010/07/improved_regex_for_matching_urls
Be sure to add:
# coding: utf-8
At the very top of your Ruby file where you use the above expression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment