title: Checking for file-extensions in PHP with Regular expressions
body: <p>I'm reading all the files in a single directory and I want to filter on JPG,JPEG,GIF and PNG.</p>
  
  <p>Both capital and small letters. Those are the only files to be accepted.</p>
  
  <p>I am currently using this:</p>
  
  <pre><code>$testPics = takeFiles($picsDir, "([^\s]+(?=\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF))\.\2)");
  </code></pre>
  
  <p>and the function takeFiles looks like this:</p>
  
  <pre><code>function takerFiles($dir, $rex="") {
      $dir .= "/";
      $files = array();
      $dp = opendir($dir);
      while ($file = readdir($dp)) {
        if ($file == '.')  continue;
        if ($file == '..') continue;
        if (is_dir($file)) continue;
        if ($rex!="" &amp;&amp; !preg_match($rex, $file)) continue;
        $files[] = $file;
      }
      closedir($dp);
      return $files;
    }
  </code></pre>
  
  <p>And it always returns nothing. So something must be wrong with my regex code.</p>