Domain name regex

后端 未结 3 1951
孤街浪徒
孤街浪徒 2021-01-21 19:15

Trying to extract the domain name out of URL. For example:

x <-\"https://stackoverflow.com/questions/ask\"

to: stackoverflow.com

3条回答
  •  星月不相逢
    2021-01-21 20:08

    Why not use parseURI from XML? It breaks a URL into its different elements.

    x <- "http://stackoverflow.com/questions/ask"
    library(XML)
    parseURI(x)$server
    # [1] "stackoverflow.com"
    

提交回复
热议问题