title: extracting youtbue url from html code by regex
body: <p>i have a html text Contain YouTube links and i try to Replace these links and displayed videos directly on same page But there is something wrong in my code (Videos does not appear) , I also want modified pattern to looking for all youtube links <code>youtube.com</code> <code>youtu.be</code> together </p>
  
  <p>my code :</p>
  
  <pre><code>$text = '&lt;div id="post_message_395"&gt;
  &lt;a href="https://www.youtube.com/watch?v=FM0mkgv2JWk" target="_blank"&gt;https://www.youtube.com/watch?v=FM0mkgv2JWk&lt;/a&gt;&lt;br&gt;
  &lt;br&gt;
  Bla Bla Bla Bla Bla Bla 
  &lt;br&gt;
  &lt;a href="https://youtu.be/FM0mkgv2JWk" target="_blank"&gt;https://youtu.be/FM0mkgv2JWk&lt;/a&gt;&lt;br&gt;
  &lt;br&gt;
  Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla 
  &lt;/div&gt;';
  $reg_exUrl = '#(?:&lt;a[^\&lt;\&gt;]+href=\")?(?:http://)?(?:[a-zA-Z]{1,4}\.)?youtube.com/watch\?v=(.{11}?)[^"]*(?:\"[^\&lt;\&gt;]*&gt;)?([^\&lt;\&gt;]*)(?:&lt;/a&gt;)?#';
  preg_match_all($reg_exUrl, $text, $matches);
  $links = $matches[2];
  
  foreach ($links as $val) 
  {
  $turl= '&lt;object width="425" height="350"&gt;
  &lt;param name="movie" value="'.$val.'&amp;rel=0"&gt;&lt;/param&gt;
  &lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param  name="allowscriptaccess" value="always"&gt;&lt;/param&gt;
  &lt;embed src="'.$val.'&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" allownetworking="internal" width="580" height="420"&gt;
  &lt;/embed&gt;
  &lt;/object&gt;';  
  $text = str_replace($val,$turl,$text); 
  }
  echo $text; 
  </code></pre>
  
  <p>outpot : </p>
  
  <p><a href="https://i.stack.imgur.com/IUzPm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IUzPm.png" alt="http://st3.pictub.club/2016/06/23/Capture123.png"></a></p>