title: How to match a word after a certain character with out knowing the word in R?
body: <p>I would to like to match the word after a <code>-</code> in my text then if that matched word is the end of another word then I would like to do a split between the word and the matched word.</p>
  
  <p>Example of the text:</p>
  
  <pre><code>JOHN LION - XYZ RAN RUN TREEABC GRASS - ABC LIMB RAN RUN LION -XYZ JOG SUN
  SKY - ABC LION JOHN PONDABC RUN - PDF STONE
  </code></pre>
  
  <p>what I would like the text to look like:</p>
  
  <pre><code>JOHN LION - XYZ RAN RUN TREE ABC GRASS - ABC LIMB RAN RUN LION -XYZ JOG SUN
  SKY - ABC LION JOHN POND ABC RUN - PDF STONE
  </code></pre>
  
  <p>I do not not want to do a <code>grepl</code> and a <code>gsub</code> on <code>ABC</code> because the word after the dash is always changing and will appear multiple times. Also the word that is in front of the matched word will also always be different and will not always be <code>TREE</code>. No matter what the word is in front of the matched word I always want to do a split.</p>
  
  <p>If I do the following str_extract:</p>
  
  <pre><code>str_extract(df, "(?&lt;=-\\s)\\w+")
  </code></pre>
  
  <p>Then I match <code>XYZ</code> not <code>ABC</code>.</p>
  
  <p>I only want to match the word after the <code>-</code> if it is also at the end of another word, but again I do not know what that other word will be.</p>
  
  <p>I am stuck as what to do. Please let me know if any further information is needed. Any help will be greatly appreciated. </p>