This is the REGEX: [^\/]+$
you would like to use to extract the last part of a URL also known as the handle
I often use this to compare URLs that are localized and end with the same handle.
How to use [^\/]+$
REGEX in Google Spreadsheet?
To use it on a Google Spreadsheet you can enter the formula =REGEXEXTRACT() and select in first the URL or the cell where the URL is & then you can use the [^\/]+$ REGEX
.
Let's say you have a column A:A
with all your URLs, for A2 (A1 being the header column URL), you have the following URL https://arthur.camberlein.com/blogs/articles/remove-x-characters-from-a-cell-in-excel in the column B:B
you could use the following formula on B2 to extract remove-x-characters-from-a-cell-in-excel
.
=REGEXEXTRACT(A2, "[^\/]+$")
Then you can drag down B2 into the rest of the B:B
column.
How does this REGEX work?
This is how it works:
-
[^\/]
: This is a character class that matches any character that is not a forward slash(/)
- The caret
(^)
at the start of the character class negates it - The
\/
is just a forward slash, but it needs to be escaped with a backslash because forward slashes have special meaning in regular expressions. -
+
: This is a quantifier that means "one or more" - so
[^\/]+
matches one or more of any character that is not a forward slash -
$
: This is an anchor that matches the end of the string.