내 URL에서 호스트를 추출하고 마지막/선택 사항을 지정하여 혼란스러워지고 있습니다. 정규 표현식은 다음을받을 수 있도록 준비 할 필요가 :regexp를 사용하여 url의 호스트 부분을 추출하는 가장 좋은 방법은 무엇입니까?
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