title: Regex to get filename with or without extension from a path
body: <p>Looking for a regex to extract out the filename part excluding the extension from a path in this code</p>
  
  <pre><code>String filename = fullpath.replaceFirst(regex, "$1")
  </code></pre>
  
  <p>e.g. for starter, here is the most simple case and what I have done:</p>
  
  <ul>
  <li>/path/filename.ext -> filename (<code>fullpath.replaceFirst(".*/(.*)\\..*", "$1")</code>)</li>
  </ul>
  
  <p>Here are some more advance cases that I need help with:</p>
  
  <ul>
  <li>/filename.ext -> filename (can start with /)</li>
  <li>filename. -> filename (can end with .)</li>
  <li>/filename -> filename (can have no .)</li>
  <li>filename.ext -> filename (can have no /)</li>
  <li>filename -> filename (can have no . and /)</li>
  <li>.filename -> .filename (can start with .)</li>
  <li>/path/.filename -> .filename (can start with . right after /)</li>
  <li>filename.part1.ext -> filename.part1 (can have middle .)</li>
  <li>/path_a/path.b/ -> (empty string) (can have no filename)</li>
  <li>/path_a/path.b/filename -> filename (can have . in path before /)</li>
  </ul>
  
  <hr>
  
  <p>Edited:
  There is no actual file here and the <code>fullpath</code> does not lead to any file. It is coming from a URL request.</p>