Parsing string from URL

jdkuehne

New Member
Joined
Nov 5, 2018
Messages
8
In Excel, I need to pull part numbers from the URLs in a site map. The URLs look something like this:

http://www.mysite.com/shop/catalog/...egory3/category4/item/partnumber1/part-title1
http://www.mysite.com/shop/catalog/category1/category2/category3/item/partnumber2/part-title2
http://www.mysite.com/shop/catalog/category1/category2/item/partnumber3/part-title3
http://www.mysite.com/shop/catalog/...egory3/category4/item/partnumber4/part-title4

I need to grab the string between the "item/" and the next "/" so that the results look like this:

partnumber1
partnumber2
partnumber3
partnumber4

There can be any number of "/" before the string and any number after. The key thing is that the string to parse comes immediately after "item/" and ends before the very next "/"

I've found a number of solutions on this site that address similar situations but none seem to work for this pattern. I'm not a programmer, so I'm not sure how to approach this. The closest I've come is a solution that will start at the correct spot but then includes everything to the end of the URL.

Any help is appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

Try this, formula copied down:


Book1
AB
1http://www.mysite.com/shop/catalog/category1/category2/category3/category4/item/partnumber1/part-title1partnumber1
2http://www.mysite.com/shop/catalog/category1/category2/category3/item/partnumber2/part-title2partnumber2
3http://www.mysite.com/shop/catalog/category1/category2/item/partnumber3/part-title3partnumber3
4http://www.mysite.com/shop/catalog/category1/category2/category3/category4/item/partnumber4/part-title4partnumber4
Sheet341
Cell Formulas
RangeFormula
B1=TRIM(LEFT(SUBSTITUTE(MID(A1,SEARCH("item/",A1)+5,99),"/",REPT(" ",99)),99))
 
Upvote 0
Thanks, jtakw. I don't understand it, but it works perfectly. Is there a way to trap the condition where the "item/" string doesn't exist and return something other than "#VALUE!"?
 
Upvote 0
Yes, just add IFERROR:


Book1
AB
1http://www.mysite.com/shop/catalog/category1/category2/category3/category4/item/partnumber1/part-title1partnumber1
2http://www.mysite.com/shop/catalog/category1/category2/category3/item/partnumber2/part-title2partnumber2
3http://www.mysite.com/shop/catalog/category1/category2/category3/none/nopartnumber/part-title2
4http://www.mysite.com/shop/catalog/category1/category2/item/partnumber3/part-title3partnumber3
5http://www.mysite.com/shop/catalog/category1/category2/category3/category4/item/partnumber4/part-title4partnumber4
Sheet341
Cell Formulas
RangeFormula
B1=IFERROR(TRIM(LEFT(SUBSTITUTE(MID(A1,SEARCH("item/",A1)+5,99),"/",REPT(" ",99)),99)),"")
 
Upvote 0
You're welcome, welcome to the forum.
 
Upvote 0
You could also make sure that it doesn't fail:
=TRIM(LEFT(SUBSTITUTE(MID(A1,SEARCH("item/",A1&"item/")+5,99),"/",REPT(" ",99)),99))


Excel 2010
AB
1http://www.mysite.com/shop/catalog/category1/category2/category3/category4/item/partnumber1/part-title1partnumber1
2http://www.mysite.com/shop/catalog/category1/category2/category3/item/partnumber2/part-title2partnumber2
3http://www.mysite.com/shop/catalog/category1/category2/category3/none/nopartnumber/part-title2 
4http://www.mysite.com/shop/catalog/category1/category2/category3/category4/item/partnumber4/part-title4partnumber4
Sheet1
Cell Formulas
RangeFormula
B1=TRIM(LEFT(SUBSTITUTE(MID(A1,SEARCH("item/",A1&"item/")+5,99),"/",REPT(" ",99)),99))
B2=TRIM(LEFT(SUBSTITUTE(MID(A2,SEARCH("item/",A2&"item/")+5,99),"/",REPT(" ",99)),99))
B3=TRIM(LEFT(SUBSTITUTE(MID(A3,SEARCH("item/",A3&"item/")+5,99),"/",REPT(" ",99)),99))
B4=TRIM(LEFT(SUBSTITUTE(MID(A4,SEARCH("item/",A4&"item/")+5,99),"/",REPT(" ",99)),99))
 
Last edited:
Upvote 0
Thanks, Scott, for the alternate solution. I think I prefer jtakw's in this instance because it allows the error condition to be replaced by any string, which should be useful for my end purpose.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top