0

I have the following string :-

http://myapp.local/myapp/shop/products/admin/ShopProducts%5Bproduct_name%5D//ShopProducts%5BemailNotification%5D//ShopProducts%5Bemail_user%5D//ShopProducts%5Bactive%5D//ShopProducts%5Binstant_win%5D//ShopProducts%5Bmulti_buy%5D//ShopProducts%5Bprice%5D//ShopProducts%5Bquantity%5D//ShopProducts_page/2/ajax/shopproducts-grid

I only want to grab the last section as so on.. not this is a part of pager (needs some weird custom hack) and the page number in this case is 2 but could 2,3,4, 500...

ShopProducts_page/2/ajax/shopproducts-grid

What is the easiest way to do this using vanilla js or jquery or a structured way to grab the parts into some of an array that I'll be able to manipulate?

3
  • Can you post some examples of things you have tried already? Commented Sep 5, 2014 at 15:26
  • 1
    will there always be some double slashes // in the path? Commented Sep 5, 2014 at 15:26
  • Dose /ShopProducts_page\/[0-9]+\/ajax\/shopproducts\-grid/ make sense? Commented Sep 5, 2014 at 15:28

1 Answer 1

2

If there will always be double forward-slashes // in the path, you can simply do this:

//Where string is already defined to be the path
var sections = string.split('//');
var lastSection = sections[sections.length-1];
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was thinking, and of course the string is window.location.pathname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.