0

i have a string like this

var url="http://localhost/elephanti2/chaink/stores/stores_ajax_page/5/b.BusinessName/asc/1/11"

i want to get the string after the 7 th slash(/)

here it would be 5/b.BusinessName/asc/1/11

2 Answers 2

1

You don't need jquery for this, just pure JS.

var url= "http://localhost/elephanti2/chaink/stores/stores_ajax_page/5/b.BusinessName/asc/1/11"
re = /^([^\/]*\/){7}(.+)/
result = url.match(re)[2]

Regular expressions in javascript: http://www.regular-expressions.info/javascript.html

Sign up to request clarification or add additional context in comments.

Comments

0

Rather than counting slashes, you should probably look for the part of the path right after a marker such as this:

var url="http://localhost/elephanti2/chaink/stores/stores_ajax_page/5/b.BusinessName/asc/1/11";
var endPath = url.replace(/^.*\/stores_ajax_page\//, "");

This is a little less brittle if the front part of the path ever gets changed.

4 Comments

hmm in this case the name stores_ajax_page changes , so i can not use , this , anyway thankyou very much ........... :)
@KanishkaPanamaldeniya - Wouldn't you still be better off anchoring to some part of the path rather than counting slashes?
mmm your script is not working --->>> unterminated regular expression var endPath = url.replace(/^.*\/stores_ajax_page\/, "");
@KanishkaPanamaldeniya - I fixed a typo in the regular expression.

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.