I need to get the string that is inside the last two bars (heDA6Yu7hsc) with javascript. How to proceed?
https://i.ytimg.com/vi/heDA6Yu7hsc/img.jpg
I need to get the string that is inside the last two bars (heDA6Yu7hsc) with javascript. How to proceed?
https://i.ytimg.com/vi/heDA6Yu7hsc/img.jpg
Try this way below:
var url="https://i.ytimg.com/vi/heDA6Yu7hsc/img.jpg";
var part = url.split("/");
console.log(part[4]);
Each part of the generated array corresponds to a break of split
[0]=https:
[1]=
[2]=i.ytimg.com
[3]=vi
[4]=heDA6Yu7hsc
[5]=img.jpg
You can also do it by regular expression.
var texto = /\/([\w\d]+)\/[\w.]+$/gi.exec("https://i.ytimg.com/vi/heDA6Yu7hsc/img.jpg");
console.log(texto[1]);