title: How to validate hdfs result with python regex to find out if it is a folder, file or non exist
body: <p>I have a str which is the result of hdfs command to show, for a given path, if it is a folder, or a file, or doesn't exist, here are examples:</p>
  
  <p>str_file:</p>
  
  <pre><code>-rw-rw----+  3 jdoe clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/part-00000-994917013a6a-c000.snappy.parquet
  </code></pre>
  
  <p>str_folder:</p>
  
  <pre><code>Found 3 items
  -rw-rw----+  3 jdoe clouderausersdev          0 2018-02-05 16:41 hdfs://nameservice1/client/abc/_SUCCESS
  -rw-rw----+  3 jdoe clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/part-00000-994917013a6a-c000.snappy.parquet
  -rw-rw----+  3 jdoe clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/part-00001-994917013a6a-c000.snappy.parquet
  -rw-rw----+  3 jdoe clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/part-00002-994917013a6a-c000.snappy.parquet
  </code></pre>
  
  <p>str_nonexist:</p>
  
  <pre><code>ls: `hdfs://nameservice1/client/abc/part-00000.parqu': No such file or directory
  </code></pre>
  
  <p>Now that I want to know the result with regex check, here is the problem:</p>
  
  <pre><code>import re
  
  regex_folder = "Found [1-9]\d items"
  regex_file = ".parquet"
  regex_error = "No such file"
  </code></pre>
  
  <p>Testing result is as below:</p>
  
  <p><a href="https://i.stack.imgur.com/4Pgpf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Pgpf.png" alt="enter image description here"></a></p>
  
  <p>So, how do I tell the difference between m and m1? apparently m means no finding while m1 means there is match.</p>
  
  <p>Eventually I need to tell the three scenarios: folder, file, nonexist</p>
  
  <p>Thank you very much.</p>
  
  <p>Update (as per Филип Димитровски):</p>
  
  <p>Still now working:m1 should show a match and m should not.</p>
  
  <p><a href="https://i.stack.imgur.com/boBVp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/boBVp.png" alt="enter image description here"></a></p>