简体   繁体   中英

Formula to extract number string between the nth instance of character to the next specific character (retrieving ID from URL)

I need to write a formula that can retrieve the number between the 4th "/" to the next "-"

Here's an example of the URL structure

https://www.example.com/category-name/1234-product-name

I've managed to get it done when the category name is ONE word like following URL with formula below. https://www.example.com/category/1234-product-name

=MID(LEFT(A2,FIND("-",A2)-1),FIND("#",SUBSTITUTE(A2,"/","#",4))+1,255)

Result = 1234

The problem is that I can't rely on the category name always being one word... And the product name can also vary in characters so i can't start from right counting the "-"

Any tips & tricks? :)

You need the break the problem and then solve it.

=MID(B1,FIND("/",B1)+1, IFERROR(FIND("-",B1,FIND("/",B1)), LEN(B1) + 1)  - FIND("/",B1)-1)

Explanation

=MID(TEXT, STARTING CHARACTER, NO OF CHARACTERS)

=MID(TEXT ,   WHERE FIRST '/' EXISTS   ,   WHERE '-' EXISTS   -   WHERE FIRST '/' EXISTS )

and for removing the domain

=REPLACE(A1,1,LEN("https://www.example.com/"),"")

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM