Google Sheet formula

onedaydayone

Regular Member
Joined
Aug 5, 2019
Messages
284
Reaction score
93
What's the formula to delete all text after "/" ?

For example, I want to exclude the domain name from all URL path: "domain.com/blog/questions/how-to-x/" > "domain.com".

I've tried several different formulas, but I always get errors...
 
What's the formula to delete all text after "/" ?

For example, I want to exclude the domain name from all URL path: "domain.com/blog/questions/how-to-x/" > "domain.com".

I've tried several different formulas, but I always get errors...

In Excel or Google Sheets​

You can use a formula based on the LEFT and FIND functions. Assuming the URL is in cell A1, the formula in Excel or Google Sheets would be: =LEFT(A1, FIND("/", A1)-1)

However, this formula only works if there's a "/" in the URL. URLs often start with "http://" or "https://", so you'd want to remove everything after the third "/". A more complex formula is needed to handle typical URLs properly:
=LEFT(A1, FIND("///", SUBSTITUTE(A1, "/", "///", 3))-1)

This formula replaces the third occurrence of "/" with "///" and then finds the position of "///" to determine where to cut the string.

This will indeed fix your issue.

Thanks!
 
I'm still getting an error. I've just created a new blank sheet, put the URL in A1, and wrote: =LEFT(A1, FIND("/", A1)-1)

Maybe there are general settings that might be turned off for me?
 
The formula, =LEFT(A1, FIND("/", A1)-1), aims to extract everything in the URL before the first slash. If you're encountering an error, it's likely because the URL in A1 does not contain a slash, causing the find function to return an error. To address this, you can use the IFERROR function to handle cases where no slash is found, like so: =IFERROR(LEFT(A1, FIND("/", A1)-1), A1) This formula will return the original URL in A1 if an error occurs (e.g., if no slash is found). Make sure the URL includes a protocol (like "http://") since the formula expects a slash to be present. If your URLs are starting directly with "www" and do not include "http://", the formula might not work as expected because it's looking for the first slash, which typically follows the protocol.

Thanks!
 
Who could help me with this formula by providing the exact formula? I will give you access to the sheet.
 
Back
Top