url: http://xxxxxx.com/video/view/12345
Can I take 12345 in the url using javascript?
Please help me
url: http://xxxxxx.com/video/view/12345
Can I take 12345 in the url using javascript?
Please help me
Use RegExp
, Array#match
and negative lookahead.
var str = 'http://xxxxxx.com/video/view/12345';
console.log(str.match(/(?!view\/)\d+/)[0]);
You can parse your URL with the following code. Then just get the last part.
var url = 'http://xxxxxx.com/video/view/12345';
var url_parts = url.replace(/\/\s*$/,'').split('/');
console.log(url_parts[url_parts.length - 1]); // last part
You can also try this if you're sure that it'll always be in last:
var num = location.pathname.split('/').pop(); // "12345"
and further: parseInt(num);