[英]Regex to capture string between slashes
I want to capture show name which is between /
/
我想捕获显示名称
/
/
http://www.voot.com/shows/
splitsvilla-s09 /1/411756/love-turns-sour/425120
http://www.voot.com/shows/
splitsvilla-s09 /1/411756/love-turns-sour/425120
I tried 我试过了
window.location.href.split('/')[4];
How to capture the highlighted part? 如何捕获突出显示的部分?
Try this: 尝试这个:
var url = "http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120";
var name = /shows\/([^\/]+)/.exec(url)[1];
Try it: 试试吧:
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("/",""));
Try this 尝试这个
var str = "http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120"
str.match(/shows\/\w+/g).join('').split('/')[1]
Just for completeness, a proposal with String#match
: 出于完整性考虑,建议使用
String#match
:
var url = 'http://www.voot.com/shows/splitsvilla-s09/1/411756/love-turns-sour/425120'; console.log(url.match(/shows\\/([^\\/]*)/)[1]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.