Last active
October 25, 2025 19:13
-
Star
(300)
You must be signed in to star a gist -
Fork
(50)
You must be signed in to fork a gist
-
-
Save gruber/249502 to your computer and use it in GitHub Desktop.
Revisions
-
gruber revised this gist
Feb 11, 2014 . No changes.There are no files selected for viewing
-
gruber renamed this gist
Feb 11, 2014 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,15 @@ The regex patterns in this gist are intended to match any URLs, including "mailto:[email protected]", "x-whatever://foo", etc. For a pattern that attempts only to match web URLs (http, https), see: https://gist.github.com/gruber/8891611 # Single-line version of pattern: (?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`!()\[\]{};:'".,<>?«»“”‘’])) # Multi-line commented version of same pattern: (?xi) \b -
gruber revised this gist
Jul 27, 2010 . 1 changed file with 25 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,34 @@ Single-line version of pattern: (?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`!()\[\]{};:'".,<>?«»“”‘’])) Extended version of same pattern: (?xi) \b ( # Capture 1: entire matched URL (?: [a-z][\w-]+: # URL protocol and colon (?: /{1,3} # 1-3 slashes | # or [a-z0-9%] # Single letter or digit or '%' # (Trying not to match e.g. "URI::Escape") ) | # or www\d{0,3}[.] # "www.", "www1.", "www2." … "www999." | # or [a-z0-9.\-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash ) (?: # One or more: [^\s()<>]+ # Run of non-space, non-()<> | # or \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels )+ (?: # End with: \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels | # or [^\s`!()\[\]{};:'".,<>?«»“”‘’] # not a space or one of these punct char ) ) -
gruber revised this gist
Dec 6, 2009 . 1 changed file with 10 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,25 @@ (?xi) \b ( # Capture 1: entire matched URL (?: [a-z][\w-]+: # URL protocol and colon (?: /{1,3} # 1-3 slashes | # or [a-z0-9%] # Single letter or digit or '%' # (Trying not to match e.g. "URI::Escape") ) | # or www\d{0,3}[.] # "www.", "www1.", "www2." … "www999." ) (?: # One or more: [^\s()<>]+ # Run of non-space, non-()<> | # or \([^\s()<>]+\) # a matching set of parens )+ (?: # End with: \([^\s()<>]+\) # a set of parens | # or [^`!()\[\]{};:'".,<>?«»“”‘’\s] # not a space or one of these punct chars ) ) -
gruber revised this gist
Dec 5, 2009 . 1 changed file with 19 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,29 @@ (?x) \b ( # Capture 1: entire matched URL (?: [\w-]+: # URL protocol and colon (?: /{1,3} # 1-3 slashes | # or [[:alpha:][:digit:]] # Single letter or digit # (Try not to match, say "URI::Escape") ) | # or www\d?[.] # "www.", "www1.", "www2.", etc. ) (?: # One or more: [^\s()<>]+ # Run of non-space, non-()<> | # or \([^\s()<>]+\) # a matching set of parens )+ (?: # End with: \([^\s()<>]+\) # a set of parens | # or (?: [^[:punct:]\s] # a non-punctuation non-space char | # or / # a slash ) ) ) -
gruber created this gist
Dec 5, 2009 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ (?x) \b ( # Capture 1: entire matched URL (?: [\w-]+: # URL protocol and colon (?: /{1,3} # 1-3 slashes | # or [[:alpha:][:digit:]] # Single letter or digit # (Try not to match, say "URI::Escape") ) | # or www\d?[.] # "www.", "www1.", "www2.", etc. ) (?: # One or more: [^\s()<>]+ # Run of non-space, non-()<> | # or \([^\s()<>]+\) # a matching set of parens )+ (?: # End with: \([^\s()<>]+\) # a set of parens | # or (?: [^[:punct:]\s] # a non-punctuation non-space char | # or / # a slash ) ) )