Skip to content

Instantly share code, notes, and snippets.

@samsonjs
Created April 8, 2010 16:24
Show Gist options
  • Save samsonjs/360240 to your computer and use it in GitHub Desktop.
Save samsonjs/360240 to your computer and use it in GitHub Desktop.
urlRegex = /\b // 1. match a word boundary, i.e. whitespace or punctuation
( // 2. capture the entire URL
( [\w-]+:\/\/? | www[.] ) // 3. protocol:// or www.
[^\s()]+ // 4. anything that's not whitespace, a paren, or an angle bracket
(?: // 5. non-capturing group (this is the last thing matched)
\([\w\d]+\) // 6. trailing parenthesized word containing only alnums (wikipedia)
| // or
( [^-!"#$%&'()*+,./:;?@[\\\]^_`{|}~\s] // 7. [^[:punct:]\s] -- anything but punctuation or whitespace
| // or
\/ // 8. a trailing slash
)
)
)
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment