What's the problem with regex?
-
There is this expression
/https:\/\/i\.ytimg\.com\/vi\/([a-zA-Z0-9_-]+)\/maxresdefault\.jpg/i
search for YouTube id follows the link of the picture. I make the expression look for the standard linkhttps://youtu.be/KkcrQTqr9q4
like this -
but it doesn't work. Where is the mistakelet regexp = /https:\/\/youtu\.be\/\([a-zA-Z0-9_-]+)/;
JavaScript Anonymous, Apr 24, 2020 -
In the code, you get the video__media element, assign it to the media variable, and then write
let url = media.src;
. Apparently, this is an ifram, and here is an error, you need to get the value in src like this:let url = media.getAttribute ('src');
should workAnonymous -
You have escaped the opening parenthesis and it has changed from a service symbol for the beginning of a group into a regular expression symbol.Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!