我想捕捉/
/
http://www.voot.com/shows/
的 splitsvilla-S09 /1/411756/love-turns-sour/425120
我试过
window.location.href.split('/')[4];
如何捕捉突出显示的部分?
答案 0 :(得分:1)
试试这个:
var url = "http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120";
var name = /shows\/([^\/]+)/.exec(url)[1];
答案 1 :(得分:1)
试一试:
var string = "http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120"
var matches = string.match(/(\/[\w+-]+)/g);
console.log(matches[2].replace("/",""));
答案 2 :(得分:0)
试试这个
var str = "http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120"
str.match(/shows\/\w+/g).join('').split('/')[1]
答案 3 :(得分:0)
为了完整起见,提案String#match
:
var url = 'http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120';
console.log(url.match(/shows\/([^\/]*)/)[1]);