Create the shortest regular expression that will roughly match a URL in text when run in JavaScript
Example:
"some text exampley.com".match(/your regular expression goes here/);
The regular expression needs to
- capture all valid URLS that are for http and https.
- not worry about not matching for URL looking strings that aren't actually valid URLS like 'super.awesome/cool'
- be valid when run as a JavaScript regex
Test criteria:
Match:
- http://example.com
- http://example.com/
- http://example.com/super
- https://example.com/super
- example.com/super
- example.com
- example.com/su-per_duper/?add=yes&subtract=no
- example.com/archive/index.html
- twitter.com/#!/reply
- example.com/234ret2398oent/234nth
- codegolf.stackexchange.com/questions/464
- crazy.wow.really.example.com/?cat=nth%3E
- example-example.com
- example1.com
Not Match:
- example
- super/cool
- Good Morning
- i:can
- hello.
Here is a test that might help clarify a bit http://jsfiddle.net/MikeGrace/gsJyr/
I apologize for the lack of clarity, I hadn't realized how awful matching URLs was.
\w
for everything Do you expect backreferences for different URL components? – SHiNKiROU Feb 4 '11 at 5:49/:/
as the regular expression and match valid URIs and not match all your examples on the »Not match« list. As long as you're going that route it's simply the question: What is the shortest regular expression that will not match any of the example strings but still catch all URIs. – Јοеу Feb 4 '11 at 9:10