Skip to content

Instantly share code, notes, and snippets.

@boy-jer
Forked from ryana/url_regex.rb
Last active October 24, 2015 09:47
Show Gist options
  • Save boy-jer/dfba275d41403f7acbb3 to your computer and use it in GitHub Desktop.
Save boy-jer/dfba275d41403f7acbb3 to your computer and use it in GitHub Desktop.
@gruber's improved regex for matching URLs written in Ruby
# From @gruber http://daringfireball.net/2010/07/improved_regex_for_matching_urls
#http://ryanangilly.com/post/8654404046/grubers-improved-regex-for-matching-urls-written
UrlRegex = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\`!()\[\]{};:\'\".,<>?«»“”‘’]))/i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment