Get Youtube Id from youtube embed using Regex [duplicate] - regex

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php regex - find all youtube video ids in string
How can I get the youtube Id from the embed using Regex, even it is in old format or ifarme
example
<iframe width="560" height="315" src="http://www.youtube.com/embed/ghc8cYOA1Vo" frameborder="0" allowfullscreen></iframe>
or
<object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/ghc8cYOA1Vo?hl=en_US&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ghc8cYOA1Vo?hl=en_US&version=3" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>
please advice,

youtube.com/((v|embed)/)?[a-zA-Z0-9]+
Youtube has recently gone from 10-character IDs to 11 characters, and it's possible that they may eventually increase that number.

Using the regexp youtube[.]com/(v|embed)/([^"?]+), the YouTube ID will be captured in the second group.
DEMO

I tested this regex ((v|embed))\/?[a-zA-Z0-9_-]+ and it works fine

Related

Interpreting A Regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I am new to Regular expressions and I came across this piece of code in Wordpress but I have failed to understand what's going on, despite the comments. Kindly help me figure it out.
// catch base url
preg_match('/href="(.+?)"/i', $content, $matches);
$baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
// get the first image from content
preg_match('/<img.+?src="(.+?)"[^}]+>/i', $content, $matches);
$img_url = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
Here's what $content contains.
<![CDATA[<p>Buganda Road Chief Magistrate James Mawanda Eremye has released Makerere University administrator Edward Kisuze. The suspended administrator is accused of sexually harassing a student. Court told Kisuzze to pay cash bail of Shs2m and each of his three sureties Shs10m.</p>
<p><img class="alignnone wp-image-32386" src="http://matookerepublic.com/wp-content/uploads/2018/04/kisuze-300x175.png" alt="" width="680" height="396" srcset="http://matookerepublic.com/wp-content/uploads/2018/04/kisuze-300x175.png 300w, http://matookerepublic.com/wp-content/uploads/2018/04/kisuze-696x405.png 696w, http://matookerepublic.com/wp-content/uploads/2018/04/kisuze.png 720w" sizes="(max-width: 680px) 100vw, 680px" /></p>
<p>However, before releasing him the magistrate ordered the prosecutor to disclose to the defence the evidence to enable commencement of hearing of this case come <span data-term="goog_350196878">May 28 2018</span>.</p>
<p>On April 14, police arrested Kisuze after a viral picture of him kissing the student’s private parts in office was released online. On May 4<sup>,</sup> he appeared before court and was remanded to Luzira prison after pleading not guilty to charges.</p>
]]>
The first one /href="(.+?)"/i is used to extract the href property from an a tag.
Check out the live example: https://regex101.com/r/84dhEk/2 (the green part is the matching one)
The second one /<img.+?src="(.+?)"[^}]+>/i is used to extract the src property from a img tag.
Check out this example: https://regex101.com/r/SOPN5I/2

Regex help for Page monitor

I want to check for the particular text below in a webpage
<img class="highlights" src="http://www.carsportal.com/images/highlights/green.jpg">
Using this regex for doing so,
<img class="highlights" src="[^]*green.jpg">
I am trying to monitoring the changes on this webpage using Page Monitor(Chrome extension). I tested it here.
But its not working on this extension.
Somethings like this:
<img class="highlights" src="[^\"]*green\.jpg">

Extract html tag from content:encoded in Yahoo Pipes

This is my pipes: link
I need to get src attribute of the img tag that are inside the content:encoded
This is the content:encoded of the feed:
<p style="text-align:justify;"><img class="alignnone size-full wp-image-49549" src="http://i2.wp.com/heshootshescoores.com/wp-content/uploads/2014/08/nhl.jpg?resize=600%2C400" alt="nhl"/></p>
<p style="text-align:justify;">...etc.
So in this example I would like to extract this link: ttp://i2.wp.com/heshootshescoores.com/wp-content/uploads/2014/08/nhl.jpg?resize=600%2C400
And export this attribute to a new item.media:thumbnail like this
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/"
url="HERE GOES THE SRC ATTRIBUTE.png"/>
Is it possible to do with Yahoo! Pipes?( I was thinking about regex but I am not familiar and I don't even know where to start.)
Thank You
FU question: https://stackoverflow.com/questions/25605740/add-items-attribute-in-yahoo-pipes
(.*?)(?=src=)src=\"(.*?)\"(.*)
This will work.
See demo.
http://regex101.com/r/bJ6rZ5/3

Regex - How do I retrieve all youtube embedded block in HTML?

normally, in html, youtube can be presented as
<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/qvt_Ae1eRPo?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/qvt_Ae1eRPo?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>
My question is that what's the regex that can retrieve this "object" block from a HTML string?
Thanks
/<object.+?<\/object>/mis should work, please note that if you want a proper retrieval of HTML tags and their contents, you should really use a parser

Extract all Images from HTML whose width or height higher than a specified value - Regex

I'm trying to make a small link share function with Classic ASP like LinkedIn or Facebook.
What I need to do is to get HTML of remote URL and extract all the images whose width are greater than 50px for example.
I can crawl and take the HTML and also I can find the images with this regex:
<img([^<>+]*)>
It matches; <img src="/images/icon.jpg" width="60" height="90" style="display:none"/>
Then I'm able to extract the path but sometimes it matches <img src="/track.php" style="display:none" width="1" height="1"/> which is not a real image.
Anyway, I feel like you are gonna be mad because of classic ASP but my company ....
I know there are lots of topics about this issue and mostly, they recommend not to USE regex but I couldn't find a way to this with classic asp. Is there a component or something to this?
Regards
This will get you close:
<img [^>]*width="(0?[1-9]\d{2,}|[5-9]\d)"[^>]*>
It accepts image tags with a width of 50 or greater.
Edit: tags with unspecified widths:
<img [^>]*width="(0?[1-9]\d{2,}|[5-9]\d)"[^>]*>|<img ((?!width=)[^>])*>