我正在从我的网址中解压主机,并且由于最后/可选而陷入了僵局。 正则表达式需要准备接收下列内容:什么是最好的方式来提取正则表达式的网址的主机部分?
http://a.b.com:8080/some/path/file.txt
or
ftp://a.b.com:8080/some/path
or
ftp://[email protected]/some/path
or
http://a.b.com
or
a.b.com/some/path
and return a.b.com
所以......
(ftp://|http://)? optionally matches the first part
then it gets hairy...
so... without adding ugly (and wrong) regexp here... just in english
(everything that isn't an '@') //optional
(everything that isn't a '/' up to the first '/' IF it's there) //this is the host group that I want
(everything else that trails) //optional