Get youtube id from string (Ionic 2 | typescript)

Hii, i have a little problem, i need to write a function that get text and returns youtube id .

myFunc(text){ //some code return video_id }

for example :
the function gets:
'bla bla https://www.youtube.com/watch?v=oX1luH4K-PQ some text bla bla ’
and returns ‘oX1luH4K-PQ’

Do you have an idea how to implement it on typescript ?

Thanks in advance , and sorry for my english :slight_smile:

Try this:

getYoutubeId(input) {
  let m = input.match(/watch\?v=(\S+)/);
  return m[1];
}

Excellent !!! Thank you very much.