Parses any well-formed URI (and makes safe asumptions for commonly used bad formations), and outputs all the useful information in capture groups:
^(?:(.+?):\/\/)?(?:([^@/\n]+)@)?((?:[a-z]|[0-9]|\.)+)(?:\:([0-9]{1,5}))?([^#?\n]+)?(\?[^#\n]+)?(?:#(.+))?$
Tests:
http://[email protected]/@page/page.html?query&q=very true#fragment
http://beans.com/[email protected]/@page/page.html?query&q=very true#fragment
http://[email protected]:1000/@page/page.html?query&q=very true#fragment
http://google.com:1000/@page/page.html?query&q=very true#fragment
http://google.com/@page/page.html?query&q=very true#fragment
http://127.0.0.1/@page/page.html?query&q=very true#fragment
http://127.0.0.1:5555/@page/page.html?query&q=very true#fragment
http://[email protected]:5555/@page/page.html?query&q=very true#fragment
http://localhost/
http://localhost/#fragment
http://localhost:4545/
http://localhost:1234/beans@localhost:4545/?query&q=very true#fragment
http://localhost:1234@localhost:4545/?query&q=very true#fragment
google.com