Extract hostname name from string

后端 未结 28 1845
情歌与酒
情歌与酒 2020-11-22 07:15

I would like to match just the root of a URL and not the whole URL from a text string. Given:

http://www.youtube.co         


        
28条回答
  •  孤城傲影
    2020-11-22 08:11

    If you end up on this page and you are looking for the best REGEX of URLS try this one:

    ^(?:https?:)?(?:\/\/)?([^\/\?]+)
    

    https://regex101.com/r/pX5dL9/1

    It works for urls without http:// , with http, with https, with just // and dont grab the path and query path as well.

    Good Luck

提交回复
热议问题