title: Regex return file name, remove path and file extension
body: <p>I have a data.frame that contains a text column of file names. I would like to return the file name without the path or the file extension. Typically, my file names have been numbered, but they don't have to be. For example:</p>
  
  <pre><code>df&lt;-data.frame(data=c("a","b"),fileNames=c("C:/a/bb/ccc/NAME1.ext","C:/a/bb/ccc/d D2/name2.ext"))
  </code></pre>
  
  <p>I would like to return the equivalent of</p>
  
  <pre><code>df&lt;-data.frame(data=c("a","b"),fileNames=c("NAME","name"))
  </code></pre>
  
  <p>but I cannot figure out the slick regular expression to do this with gsub. For example, I can get rid of the extension with (provided the file name ends with a number):</p>
  
  <pre><code>gsub('([0-9]).ext','',df[,"fileNames"])
  </code></pre>
  
  <p>Though I've been trying various patterns (by reading the regex help files and similar solutions on this site), I can't get a regex to return the text between the last "/" and the first ".". Any thoughts or forwards to similar questions are much appreciated! </p>
  
  <p>The best I have gotten is:</p>
  
  <pre><code> gsub('*[[:graph:]_]/|*[[:graph:]_].ext','',df[,"fileNames"])
  </code></pre>
  
  <p>But this 1) doesn't get rid of all the leading path characters and 2) is dependent on a specific file extension.</p>