Explanation
In this example, the goal is to extract the domain name from a list of URLs. In the current version of Excel, the easiest way to do this is to use a formula based on the TEXTAFTER and TEXTBEFORE functions. In older versions of Excel, you can use a more complicated formula based on the LEFT and FIND functions. Both approaches are explained below.
TEXTAFTER with TEXTBEFORE
The formula in the worksheet shown uses the TEXTAFTER and TEXTBEFORE functions to extract domain names from URLs. As the names imply, the TEXTAFTER function extracts text that occurs after a given delimiter, and the TEXTBEFORE function extracts text that occurs before a given delimiter. To solve this problem, each function needs just two arguments, text and delimiter :
=TEXTAFTER(text,delimiter)
=TEXTBEFORE(text,delimiter)
- text - the text string to split
- delimiter - the place at which to split the text
In the worksheet shown, the formula in cell C5 uses both functions like this:
=TEXTBEFORE(TEXTAFTER(B5,"//"),"/")
This is an example of nesting one function inside another. Working from the inside out, the TEXTAFTER function is first used to strip the “protocol” from the URL. In this case, the protocol is the text “https://” or “http://”. To locate the protocol, we use “//” for the delimiter and provide B5 for text:
TEXTAFTER(B5,"//")
TEXTAFTER locates the double forward slash “//” and returns all text that follows. With the text “https://exceljet.net/formulas/" in cell B5, TEXTAFTER returns “exceljet.net/formulas/”. This text is then handed off directly to the TEXTBEFORE function as the text argument for further processing:
=TEXTBEFORE("exceljet.net/formulas/","/")
Here, TEXTBEFORE is configured to use a single forward slash “/” for the delimiter . TEXTBEFORE locates the single forward slash “/” and returns all previous text. The final result is the domain “exceljet.net”.
Remove the www
If you want to remove the “www” subdomain from the domain when it is extracted, you can nest the original formula inside the SUBSTITUTE function like this:
=SUBSTITUTE(TEXTBEFORE(TEXTAFTER(url,"//"),"/"),"www.","")
SUBSTITUTE is configured to replace “www.” with an empty string (”"). If “www.” is not found, SUBSTITUTE returns the original result.
Legacy Excel
In older versions of Excel without the TEXTBEFORE or TEXTAFTER functions, this is a more challenging problem. For a quick solution, you can use a formula like this:
=LEFT(B5,FIND("/",B5,9)-1)

At the core, this formula is extracting characters from the left side of the URL with the LEFT function , and using the FIND function to figure out how many characters to extract. First, FIND locates the “/” character in the URL, starting at the 9th character:
FIND("/",B5,9)
This is the “clever” part of the formula. URLs begin with something called a “protocol” which looks like this:
http:// https:// ftp:// sftp://
By starting at the 9th character, the protocol is skipped, and the FIND function will return the location of the third instance of “/”, which is the first instance after the double slash in the protocol. With the text “https://exceljet.net/formulas/" in cell B5, the third instance of “/” is the 21st character in the URL, so FIND returns the number 21. The LEFT function then extracts 21 characters from the URL, starting at the left. The result is the domain name with a trailing slash, “https://exceljet.net/". To get the domain name without a trailing slash, we subtract 1 from the result of FIND like so:
=LEFT(B5,FIND("/",B5,9)-1)
One limitation of this formula is that it leaves the protocol (i.e. “https://”) in place. To remove the protocol in a second step , you can use a formula like this:
=MID(C5,FIND("//",C5)+2,LEN(C5))
Essentially, this formula uses the MID function and the FIND function to extract text starting after the “//”. The number of characters to extract is provided by the LEN function , which returns the number of characters in cell C5. This is actually a hack to keep things simple. LEN will return 30 in this case, but there are only 20 characters left to extract after the “//”. This works because when the number of characters ( num_chars ) exceeds the remaining string length MID will extract all remaining text. Using LEN to provide num_chars is a simple way to give MID a number that is always large enough.
Explanation
In this example, the goal is to extract the name from a list of email addresses. In the current version of Excel, the easiest way to do this is with the TEXTBEFORE function or the TEXTSPLIT function. In older versions of Excel, you can use a formula based on the LEFT and FIND functions. All three options are explained below.
TEXTBEFORE function
The TEXTBEFORE function returns the text that occurs before a given delimiter. The generic syntax for TEXTBEFORE supports many options:
=TEXTBEFORE(text,delimiter,[instance_num],[match_mode],[match_end],[if_not_found])
However, most of these arguments are optional. For this problem, we only need to provide the first two arguments, text and delimiter :
=TEXTBEFORE(text,delimiter)
Text is the text string to split, and delimiter is the location at which to split the string. Since all email addresses contain the “@” character separating the name from the domain, we can extract the name with a formula like this:
=TEXTBEFORE(C5,"@")
As the formula is copied down the column, it extracts the name from each of the emails as shown in the worksheet. For more details on TEXTBEFORE, see How to use the TEXTBEFORE function .
Note: You can use the TEXTAFTER function to extract the domain from the email.
TEXTSPLIT function
Another easy way to solve this problem is with the TEXTSPLIT function , which is designed to split a text string at a given delimiter and return all parts of the split string in a single step. To solve this problem with TEXTSPLIT, use a formula like this in cell D5:
=TEXTSPLIT(C5,"@")
As the formula is copied down, TEXTSPLIT will split the email at the @ character and return the name and the domain. These two values will spill into column D and column E as seen below:

The advantage of this approach is that you get both the email and the domain with a single formula. For more details on TEXTSPLIT, see How to use the TEXTSPLIT function .
Legacy Excel
In older versions of Excel that do not provide the TEXTBEFORE or TEXTSPLIT functions, you can use a formula based on the LEFT and FIND functions:
=LEFT(C5,FIND("@",C5)-1)
At the core, this formula extracts characters from the left with the LEFT function, using FIND to figure out how many characters to extract. C5 contains the email “john.doe123@abc.com”, so FIND returns 12, since the “@” occurs as the 12th character. We then subtract 1 to prevent the formula from extracting the “@” along with the name:
FIND("@",C5)-1 // returns 11
The result is 11, which is returned directly to the LEFT function as the num_chars argument:
=LEFT(C5,11) // returns "john.doe123"
The final result returned by LEFT is “john.doe123”. As the formula is copied down the column, it performs the same operation on each email address. Although this formula is more complicated than the TEXTBEFORE or TEXTSPLIT options above, it achieves the same result.