-1

I have a url and just want to get the id:

https://web.microsoftstream.com/video/223ac74c-0a2f-4f36-b78b-a8ad8a6e3009

Guess I could just look for the '/' at the end and split up the string into substring. What would be a more elegant/better way to just get the id: 223ac74c-0a2f-4f36-b78b-a8ad8a6e3009?

bier hier
  • 20,970
  • 42
  • 97
  • 166

1 Answers1

5

You can use Array.prototype.substring or regex

let url = 'https://web.microsoftstream.com/video/112233444';
let id = url.substring(url.lastIndexOf('/') + 1);
console.log(id);

// Or using regex
id = url.match(/\d+$/)[0];
console.log(id);

// If your id is some hash or uuid then
url  = 'https://web.microsoftstream.com/video/223ac74c-0a2f-4f36-b78b-a8ad8a6e3009';
console.log(url.match(/video\/(.*)$/)[1]);
Zohaib Ijaz
  • 21,926
  • 7
  • 38
  • 60