Regex extract domain from web page


I have been scratching my head all day on this as im not a regex expert.

If i have a web address like:








These are all made up addresses :slight_smile:

I wish to be able to just extract the middle part so the first four web addresses would produce facebook, the second instagram, the third twitter and the fourth amazon

Below is the closest I have gotten to it

test <- ""

stringr::str_extract(test, '(?<=www.)(.*)(?=.)')

# ""

Thank you for your time

Hi All,

I think the below should do it

extract_website <- function(website){

  my <- str_split(website, '\\.', simplify = TRUE)
  parts <- ncol(my)
  if(website == 'missing'){
  else if(my[parts-1] %in% c('co','com','gov','net', 'org', 'edu')) {
  } else{

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.