title: PHP regular expression to match a filepath
body: <p>Can someone please help me with this <code>preg_match</code></p>
  
  <pre><code>if (preg_match('~[^A-Za-z0-9_\./\]~', $filepath))
      // Show Error message.
  </code></pre>
  
  <p>I need to match a possible filepath.  So I need to check for double slashes, etc.  Valid file path strings should look like this only:</p>
  
  <pre><code>mydir/aFile.php
  </code></pre>
  
  <p>or</p>
  
  <pre><code>mydir/another_dir/anyfile.js
  </code></pre>
  
  <p>So a slash at the beginning of this string should be checked also.  Please help.</p>
  
  <p>Thanks :)</p>
  
  <p><strong>EDIT</strong>:
  Also, guys, this path is being read from within a text file.  It is not a filepath on the system.  So hopefully it should be able to support all systems in this case.</p>
  
  <p><strong>RE-EDIT</strong>:
  Sorry, but the string can also look like this too:
  <code>myfile.php</code>, or <code>myfile.js</code>, or <code>myfile.anything</code></p>
  
  <p>How do I allow strings like this as well??  I apologize for not being too specific on this before...</p>