Given the URL (single line):
http://test.example.com/dir/subdir/file.html
How can I extract the following parts using regular expressions:
/^((?Phttps?|ftp):\/)?\/?((?P.*?)(:(?P.*?)|)@)?(?P[^:\/\s]+)(?P:([^\/]*))?(?P(\/\w+)*\/)(?P[-\w.]+[^#?\s]*)?(?P\?([^#]*))?(?P#(.*))?$/
From my answer on a similar question. Works better than some of the others mentioned because they had some bugs (such as not supporting username/password, not supporting single-character filenames, fragment identifiers being broken).