Forked from gruber/Liberal Regex Pattern for All URLs
Created
February 4, 2010 18:13
-
-
Save anttih/294938 to your computer and use it in GitHub Desktop.
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 characters
(?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}[.]) # Capture 2: "www.", "www1.", "www2." … "www999." | |
) | |
( # Capture 3: everything after "http://[www|www1...]" | |
(?: # 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 | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment