title: Regex pattern to validate Linux folder path
body: <p>Using JAVA.
  I am trying to find a more elegant way for <strong>validating a Linux folder path</strong> (not including the file name).</p>
  
  <p>What I have so far is this: <code>"^\\/$|^((\\/([a-zA-Z0-9_-]+))+)$"</code></p>
  
  <p>Folder paths should include only following characters: <em>letters</em>, <em>numbers</em>, <em>dashes</em> or <em>underscore</em>.</p>
  
  <h3>Test cases</h3>
  
  <p>Valid/ matches:</p>
  
  <ul>
  <li><code>/</code></li>
  <li><code>/abc</code></li>
  <li><code>/abc/abc/abc/abc</code></li>
  </ul>
  
  <p>Invalid / not-matches: </p>
  
  <ul>
  <li><strong>null</strong> or <strong>empty string</strong></li>
  <li><code>/abc/</code></li>
  <li><code>/abc/abc/abc/abc/</code></li>
  </ul>