title: R getting substrings and regular expressions?
body: <p>I have a set of strings that are file names. I want to extract all characters after the # symbol but before the file extension. For example, one of the file names is:</p>
  
  <pre><code>HelloWorld#you.txt
  </code></pre>
  
  <p>I would want to return the string<code>you</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code>    hashPos = grep("#", name, fixed=TRUE)
      dotPos = length(name)-3
      finalText = substring(name, hashPos, dotPos)
  </code></pre>
  
  <p>I read online that <code>grep</code> is supposed to return the index where the first parameter occurs (in this case the # symbol). So, I was expecting the above to work but it does not.</p>
  
  <p>Or how would I use a regular expression to extract this string?
  Also, what happens when the string does not have a # symbol? Would the function return a special value such as -1?</p>