How to extract the host from a URL in JavaScript?

后端 未结 5 2125
我寻月下人不归
我寻月下人不归 2021-02-12 18:20

Capture the domain till the ending characters $, \\?, /, :. I need a regex that captures domian.com in all of these.

domain.com:3000
do         


        
5条回答
  •  佛祖请我去吃肉
    2021-02-12 18:53

    I'm using Node ^10 and this is how I extract the hostname from a URL.

    var url = URL.parse('https://stackoverflow.com/q/13506460/2535178')
    console.log(url.hostname)
    //=> stackoverflow.com
    

提交回复
热议问题