简体   繁体   English

如何在特定子字符串jQuery之后获取字符串

[英]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.

相关问题 如何在javascript中的特定子字符串后获取子字符串 - How to get substring after specific substring in javascript 如何使用jQuery从字符串中获取子字符串 - how to get substring from string using jquery Javascript:如何在 // 之后和之前获取字符串的 Substring - Javascript: How to get Substring of a string after // and before javascript-如何从最后一次看到特定字符后的字符串中获取子字符串? - How to get substring from string after last seen to specific characer in javascript? 如何在 JavaScript 中的最后一个特定字符之后获取子字符串? - How to get substring after last specific character in JavaScript? 如何从 javascript 或 jquery 中的字符串中的两个 [] 大括号之间获取 substring - How to get the substring from between two [ ] braces in a string in javascript or jquery 如果所述子字符串在两个特定字符之间,如何获取字符串的子字符串 - How to get substring(s) of a string if said substring(s) are between two specific characters 如果 substring 存在于字符串中,如何获取接下来的 3 个字符? - How to get next 3 characters after a substring if it exist inside a string? 在JavaScript中删除子字符串后如何获取剩余的字符串? - How to get remaining string after substring deletion in JavaScript? 如何从第二个连字符后的字符串子字符串中获取? - How to get from the string substring after second hyphen?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM