[英]how to get the string after specific substring jquery
我有這樣的字符串
var url="http://localhost/elephanti2/chaink/stores/stores_ajax_page/5/b.BusinessName/asc/1/11"
我想在第7 th slash(/)
之后獲取字符串
這是5/b.BusinessName/asc/1/11
您不需要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]
javascript中的正則表達式: http : //www.regular-expressions.info/javascript.html
與其計算斜線,不如直接在路徑標記的后面尋找這樣的部分:
var url="http://localhost/elephanti2/chaink/stores/stores_ajax_page/5/b.BusinessName/asc/1/11";
var endPath = url.replace(/^.*\/stores_ajax_page\//, "");
如果路徑的前部曾經改變過,那么它的脆性會降低一些。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.