How do I change the regexp?

  • 0
    Good evening! I found a code for my project that searches for the id of a YouTube video by regexp and inserts this excerpt in a certain place.
    function parseMediaURL(media) {
        let regexp = /https:\/\/i\.ytimg\.com\/vi\/([a-zA-Z0-9_-]+)\/maxresdefault\.jpg/i;
        let url = media.src;
        let match = url.match(regexp);
    
        return match[1];
    }

    from this link
    https://i.ytimg.com/vi/neHA4MJwpnY/maxresdefault.jpg

    How to make it find id from any link, not id from the image path.
    For example, from this link https://youtu.be/KkcrQTqr9q4
    JavaScript Natalie Stokes, Mar 31, 2019

  • 2 Answers
  • 0
    Here are a couple of regulars that go over all the links I know of jsfiddle.net/1j5do56g/1
    Anonymous

  • 0
    the captain suggests that vi \ is not a vindette)))
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!