【问题标题】:Extract domain name without suffix or subdomain提取没有后缀或子域的域名
【发布时间】:2017-01-09 02:40:17
【问题描述】:

我有一个包含一些域名的表格

    site
1 Google.com
2 yahoo.in
3 facebook.com
4 badge.net

所以,我想删除“。”之后的所有单词。例如(.com、.net、.in)。 我使用了下面的函数,但是将我的字符串转换为数字形式。

gsub("\\..*","",df)

【问题讨论】:

标签: regex r string


【解决方案1】:

您正在使用域名,因此您可能需要使用一些专门为此而设计的工具:

library(urltools)

df <- data.frame(site=c("Google.com", "yahoo.in", "facebook.com", "badge.net"))

suffix_extract(df$site)
##           host subdomain   domain suffix
## 1   Google.com      <NA>   google    com
## 2     yahoo.in      <NA>    yahoo     in
## 3 facebook.com      <NA> facebook    com
## 4    badge.net      <NA>    badge    net

对于@Sotos:

urltools::suffix_extract('www.bankofcyprus.com')
##                   host subdomain       domain suffix
## 1 www.bankofcyprus.com       www bankofcyprus    com

【讨论】:

  • 是的,谢谢,我只需要域,但现在我可以从这个解决方案中提取它。
猜你喜欢
  • 2013-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多