As an addentum to @amon's excellent answer:
The Expression Library of the Expresso RegEx tool has this pattern for URL's (C# syntax):
Putting it against @amon's test cases yields these results:
Stuff in parentheses isn't captured, nor IPV6 IP's. But I'd consider it a good starting point with fewer false positives, and it also matches all the common URL's in this question.
- Use numbered capture groups to distinguish the URL parts. It makes it a little easier to debug a regular expression that doesn't do what it's supposed to be doing.
- Depending on how the result is used, I would also add a group that captures the query string independently, if the URL has one.