Home » Javascript » Grab url iframe string using regex

Grab url iframe string using regex

Posted by: admin August 19, 2018 Leave a comment

Questions:

String

let iframe = "<iframe src=\"https://player.vimeo.com/video/111111\" width=\"500\" height=\"281\" frameborder=\"0\" allowfullscreen></iframe>";

What I need is the src url string.

I’ve tried an expression that gets most of it.

let url = iframe.match(/\bhttps?:\/\/\S+);

This returns

'https://player.vimeo.com/video/111111\"'

It’s returning the final \ and ” which I don’t want. I’ve tried to use something like

[^\"]

to say “don’t include the \ or ” but I’m not getting it right.

Regex is always a bear for me.

Answers: