title: Regex to parse file name in Java
body: <p>I am trying to parse a file name according to a given pattern but not able to perfect the match. Here is a sample file name:</p>
  
  <pre><code>CRS-ISAU-RPV#3430_Dedalus_Conc.ok.erto_AOTreviglio.doc
  </code></pre>
  
  <p>And here are my requirements:</p>
  
  <p>til the character <code>#</code> the file name can contain anything, after <code>#</code>, i have to find character <code>_</code> or the character <code>-</code> to separate a string. The string in between the character(optionally <code>_</code> or <code>-</code> - but not both) can contain any other character. So eventually after the character <code>#</code> i must have exactly three (3) <code>_</code> or <code>-</code> characters combined. The string should end with <code>.doc</code> or <code>.docx</code> or <code>.odt</code> but NOT <code>.ok.doc</code> or <code>.ok.docx</code> or <code>.ok.odt</code>.</p>
  
  <p>Here is what i tried:</p>
  
  <pre><code>(.*)#([^_-]+)[_-]([^_-]+)[_-]([^_-]+)[_-]([^_-]+)\.[doc|odt|docx].*(?&lt;!\.ok)$
  </code></pre>
  
  <p>But this forces me to end the string with <code>.doc.ok</code> or <code>.docs.ok</code> or <code>.docx.ok</code> and actually i want to retain the file extension at the end.</p>
  
  <p>If i try this:</p>
  
  <pre><code>(.*)#([^_-]+)[_-]([^_-]+)[_-]([^_-]+)[_-]([^_-]+)\..*(?&lt;!ok\.[doc|odt|docx])$
  </code></pre>
  
  <p>it wont work.</p>
  
  <p>Any help would be appreciated. Thank you :)</p>