title: PHP Regex - Video files direct links and YouTube links
body: <p>I'm trying to create a regular expression which should match URLs that point directly to *.mp4 file <strong>or</strong> a YouTube video, using PHP.</p>
  
  <p>I've created successfully a regex which matches only a YouTube video and another regex for matching only a direct *.mp4 file, now I want to combine them, which is currently failing.</p>
  
  <p>The requirements of a match is that it has to match a URL with and without http(s) and/or www. So for example the following links should be valid:</p>
  
  <pre><code>https://www.example.com/files/video.mp4
  http://www.example.com/files/video.mp4
  https://example.com/files/video.mp4
  http://example.com/files/video.mp4
  www.example.com/files/video.mp4
  www.youtube.com/watch?v=xxxxxx
  www.youtu.be/watch?v=xxxxxx
  </code></pre>
  
  <p>I'm using regex101.com for testing and the explanations. At the moment some links are valid according to this tester website, and some links are incorrect while they should be correct actually.</p>
  
  <p>Is there somebody who can tell me whats wrong with <a href="https://regex101.com/r/PWh4IQ/1" rel="nofollow noreferrer">my regex</a>?</p>
  
  <pre><code>(http(s)?:\/\/|(w){3}).*\.((?:mp4)|).*(youtu(be|.be))?(\.com)?\/.+
  </code></pre>