Search code examples
regexurlgoogle-sheetsgoogle-sheets-formulaarray-formulas

Google Sheets Formula for Extracting Domain From Website?


REGEXEXTRACT(A1:A,"(?m)http(?:s?):\/\/.*?([^\.\/]+?\.[^\.]+?)(?:\/|$)")

Trying to extract domain from website

The formula above has worked for me if the link is like this: https://walmart.com/careers

However, it doesn't work if it's already a domain (walmart.com) or if it's www.walmart.com/careers

Is there a more thorough formula that can allow for these edge cases?


Solution

  • try:

    =ARRAYFORMULA(INDEX(SPLIT(REGEXREPLACE(A8:A12, "https?://www.|https?://|www.", ), "/"),,1))
    

    0

    enter image description here


    UPDATE 1:

    =ARRAYFORMULA(IFNA(REGEXEXTRACT(INDEX(SPLIT(
     REGEXREPLACE(A8:A14, "https?://www.|https?://|www.", ), "/"),,1), 
     "\.(.+\..+)"), INDEX(SPLIT(
     REGEXREPLACE(A8:A14, "https?://www.|https?://|www.", ), "/"),,1)))
    

    0


    UPDATE 2:

    =INDEX(IFERROR(REGEXEXTRACT(A1:A, "^(?:https?:\/\/)?(?:ftp:\/\/)?(?:www\.)?([^\/]+)")))
    

    enter image description here