Manually dissecting nested URLs in Excel to extract specific path segments is a tedious, error-prone bottleneck for digital analysts. To resolve this, organizations often rely on custom scripts or allocate standard funding sources to procure complex data-cleaning software. However, mastering native formulas grants teams immediate data autonomy without external IT costs.
Under the stipulation that your URLs maintain a consistent protocol prefix, functions like TEXTSPLIT work flawlessly-for example, instantly isolating the subfolder "blog" from domain.com/blog/article. Below, we outline the exact formula configurations to partition your web paths seamlessly.
When working with web analytics, SEO audits, or digital marketing datasets, you will frequently find yourself dealing with lists of URLs. Often, these URLs contain valuable structural data-such as subdomains, subdirectories, product categories, or specific page paths-all separated by a forward slash (/). To analyze this data effectively, you need to break down these URLs into individual components.
Depending on your version of Excel and your specific data cleaning goals, there are several ways to accomplish this. This comprehensive guide will walk you through the best Excel formulas and techniques to split a URL by a forward slash, ranging from modern dynamic array formulas to classic legacy workarounds.
TEXTSPLIT FunctionIf you are using Excel 365 or Excel 2021 (and newer), splitting text is incredibly simple thanks to the dedicated TEXTSPLIT function. This function automatically spills the split components across adjacent columns.
Assuming your URL is in cell A2, use the following formula:
=TEXTSPLIT(A2, "/")
If your URL starts with https:// or http://, the basic formula will interpret the double forward slash as an empty segment between them. This leaves an empty column in your output. To fix this, you can configure TEXTSPLIT to ignore empty values by setting its fourth argument (ignore_empty) to TRUE:
=TEXTSPLIT(A2, "/", , TRUE)
How it works:
//).If your URL is https://www.example.com/blog/seo-tips, the formula will cleanly output:
| Column B | Column C | Column D | Column E |
|---|---|---|---|
| https: | www.example.com | blog | seo-tips |
If you are using an older version of Excel (Excel 2019, 2016, or 2013) that does not support TEXTSPLIT, or if you only want to extract a specific path segment (e.g., just the 2nd folder path) into a single cell, you can use a creative combination of TRIM, MID, SUBSTITUTE, and REPT.
To extract the Nth segment from a URL in cell A2, use this formula:
=TRIM(MID(SUBSTITUTE(A2, "/", REPT(" ", len(A2))), (N-1)*len(A2)+1, len(A2)))
To make this safe for almost any URL length, we can substitute a fixed large number like 255 instead of dynamically calculating LEN(A2):
=TRIM(MID(SUBSTITUTE(A2, "/", REPT(" ", 255)), (N-1)*255+1, 255))
SUBSTITUTE(A2, "/", REPT(" ", 255)): This replaces every single forward slash in your URL with 255 spaces. This isolates each segment of text by surrounding it with massive blocks of whitespace.(N-1)*255+1: This calculates the starting position of the Nth chunk of text. For example, if you want the 3rd segment (N=3), the formula starts looking at character 511.MID(..., [start], 255): This grabs a 255-character slice of text starting from your calculated position. Because of the massive spacing, this slice is guaranteed to contain your target text surrounded by empty spaces.TRIM(...): This strips away all the leading and trailing spaces, leaving you with only the clean text of your chosen segment.Let's say cell A2 contains: example.com/products/electronics/phones. If you want to extract the category "products" (which is the 2nd segment if we split by /):
=TRIM(MID(SUBSTITUTE(A2, "/", REPT(" ", 255)), (2-1)*255+1, 255))
This will return: products.
One of the most common reasons to split a URL by a forward slash is to isolate the root domain name (e.g., extracting www.example.com from https://www.example.com/sub/page). This requires dynamic formulas to handle URLs with or without https://.
If your URLs always begin with a protocol, you can use this formula to extract everything between the double slash and the next forward slash:
=MID(A2, FIND("//", A2) + 2, FIND("/", A2 & "/", FIND("//", A2) + 2) - (FIND("//", A2) + 2))
FIND("//", A2) + 2 locates the starting position of the domain name immediately after the double slash.FIND("/", A2 & "/", FIND("//", A2) + 2) searches for the next forward slash after the domain. Appending & "/" to A2 prevents errors if the URL has no trailing slash.MID extracts the text between these two positions.For Windows users on legacy Excel versions, there is a hidden gem formula: FILTERXML. This function converts your URL string into a readable XML format, letting you query specific parts using XPath syntax.
To extract the Nth segment of a URL in cell A2, use:
=FILTERXML("<t><s>" & SUBSTITUTE(A2, "/", "</s><s>") & "</s></t>", "//s[" & N & "]")
If A2 is sports/football/news and you want to extract the second element ("football"):
=FILTERXML("<t><s>" & SUBSTITUTE(A2, "/", "</s><s>") & "</s></t>", "//s[2]")
This returns: football.
Note: This method is highly efficient but does not work in Excel for Mac or Excel Online.
Real-world URLs are rarely perfectly clean. Two common issues can disrupt your slash-splitting formulas: trailing slashes and query strings.
If your URL contains query strings (like ?utm_source=google), the final split segment will contain that query parameter. To remove query strings before splitting, wrap your URL cell reference in a LEFT and FIND function:
=IFERROR(LEFT(A2, FIND("?", A2) - 1), A2)
You can substitute this cleaned text formula inside your chosen split formula to ensure pristine results.
If a URL ends with a forward slash (e.g., example.com/blog/), a standard split may generate an annoying empty column or element at the end. You can clean trailing slashes using this logical test:
=IF(RIGHT(A2, 1) = "/", LEFT(A2, LEN(A2) - 1), A2)
| Method | Best For | Pros | Cons |
|---|---|---|---|
| TEXTSPLIT | Excel 365 / 2021+ Users | Easiest to write, dynamic spill behavior, handles empty delimiters natively. | Not backward compatible with older Excel versions. |
| SUBSTITUTE & REPT | Older Excel versions (Single target path) | Works in all Excel versions, highly reliable for extracting a single column value. | Long, complex syntax; requires manual placement tracking (N). |
| FILTERXML | Excel 2013 - 2019 (Windows) | Very elegant, mimics array behavior without 365 formulas. | Not supported on Excel for Mac or Excel Web. |
Splitting URLs by their forward slashes is a core task in modern data analysis and reporting. If you have access to Excel 365, utilizing TEXTSPLIT with the ignore empty argument is your best path forward. For backward compatibility, mastering the SUBSTITUTE and REPT hack ensures your spreadsheets remain functional across any device or version of Microsoft Excel.
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.