title: R - Extract info after nth occurrence of a character from the right of string
body: <p>I've seen many iterations of extracting w/ <code>gsub</code> but they mostly deal with extracting from left to right or after one occurrence. I am wanting to match from right to left, counting four occurrences of <code>-</code>, matching everything between the 3rd and 4th occurrence.</p>
  
  <p>For example:</p>
  
  <pre><code>string                       outcome
  here-are-some-words-to-try   some
  a-b-c-d-e-f-g-h-i            f
  </code></pre>
  
  <p>Here are a few references I've tried using:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/35088337/find-third-occurrence-of-a-special-character-and-drop-everything-before-that-in">Find third occurrence of a special character and drop everything before that in R</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/7449564/regex-return-all-before-the-second-occurrence">regex - return all before the second occurrence</a></p></li>
  </ul>