title: Regex to get YouTube URL from string
body: <p>I have the following code which grabs YouTube URLs stored in a string variable:</p>
  
  <pre><code>function getVideoUrlsFromString($html) {
      $regex = '#((?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)([a-zA-Z0-9-]*))#i';
      preg_match_all($regex, $html, $matches);
      $matches = array_unique($matches[0]);
      usort($matches, function($a, $b) {
          return strlen($b) - strlen($a);
      });
      return $matches;
  }
  
  $html = 'https://www.youtube-nocookie.com/embed/VWrlXsmcL2E';
  $html = getVideoUrlsFromString($html);
  print_r($html);
  </code></pre>
  
  <p>But it doesn't work with:</p>
  
  <pre><code>https://www.youtube-nocookie.com/embed/VWrlXsmcL2E
  http://www.youtube.com/v/NLqAF9hrVbY?fs=1&amp;hl=en_US
  </code></pre>
  
  <p>Is there any way to alter the regex to work with these 2 common YouTube URLs?</p>