Getting parts of a URL (Regex)

后端 未结 26 2555
说谎
说谎 2020-11-22 02:13

Given the URL (single line):
http://test.example.com/dir/subdir/file.html

How can I extract the following parts using regular expressions:

  1. The Subd
26条回答
  •  执笔经年
    2020-11-22 02:59

    None of the above worked for me. Here's what I ended up using:

    /^(?:((?:https?|s?ftp):)\/\/)([^:\/\s]+)(?::(\d*))?(?:\/([^\s?#]+)?([?][^?#]*)?(#.*)?)?/
    

提交回复
热议问题