Reputation: 367
I am trying to retrieve part of the src from different iframes from an HTML input.
So far, I've tried different methods but none of them works for all iframes. What I've tried so far:
<iframe(.*?)><\/iframe>
<iframe src="(.+?)".+</iframe>
<iframe.+?src=[\"'](.+?)[\"'].*?>
And here is a sample of iframe tags that I have:
<iframe src="http://www.youtube.com/embed/NM51qOpwcIM?modestbranding=1;rel=0;showinfo=0;autoplay=0;autohide=1;yt:stretch=16:9;wmode=transparent;?wmode=transparent" allowfullscreen="" style="width: 640px; height: 361.057px;" frameborder="0"></iframe>
<iframe src="https://www.youtube.com/embed/VASywEuqFd8?feature=oembed" allowfullscreen="" width="660" height="371" frameborder="0"></iframe>
Ideally, I would like to retrieve the src from the beginning and just before the first question mark (?) as such:
http://www.youtube.com/embed/NM51qOpwcIM
Upvotes: 1
Views: 7813
Reputation: 9649
This can be achieved using
(?<=src=").*?(?=[\?"])
See working example on Regex101
(?<=src=")
Prepended by src="
.*?
Lazy match any token(?=[\?"])
Until either a ?
or "
would be the next token?
(?<=src=").*?(?=[\*"])
Upvotes: 10