我有以下字符串:
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
我只想抓住最后一部分,依此类推..不是这是寻呼机的一部分(需要一些怪异的自定义技巧),这种情况下的页数是2,但是可以是2,3,4,500 ...
ShopProducts_page/2/ajax/shopproducts-grid
使用vanilla js或jquery进行此操作的最简单方法是什么,或者以结构化的方式将部件抓取到我可以操纵的数组中的某些方式?
最佳答案
如果路径中始终存在双斜杠//
,则只需执行以下操作:
//Where string is already defined to be the path
var sections = string.split('//');
var lastSection = sections[sections.length-1];
关于javascript - 使用正则表达式在js/jquery中获取字符串的一部分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25689153/