[英]how to get the string after specific substring jquery
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(/)
我想在第
7 th slash(/)
之后获取字符串
here it would be 5/b.BusinessName/asc/1/11
这是
5/b.BusinessName/asc/1/11
You don't need jquery for this, just pure JS. 您不需要jquery,只需纯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 javascript中的正则表达式: http : //www.regular-expressions.info/javascript.html
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. 如果路径的前部曾经改变过,那么它的脆性会降低一些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.