title: Is there any method replace repeating pattern specifically in R?
body: <p>I have a some string which have word and number.</p>
  
  <pre><code>[1] "\r\nfund \r\ncompany \r\nfee \r\nsales \r\ngroup \r\npayment \r\nmanagement \r\nfirm \r\nfee \r\ntotal \r\npayment \r\nsubtotal \r\nfee \r\nsynthetic \r\nfee... sth ... \r\n0.646 0.030 0.030 0.015 1.253....
  </code></pre>
  
  <p>As you can see there is a pattern which have sth~ fee, sth~ payment. 
  My ultimate goal is to group the words to make this table using scan function or else(if you have any idea please reply with this.)</p>
  
  <p>So I tried to delete all the blank because scan function (i guess) identify with some blank as standard to divide words group.</p>
  
  <p>Again I mean, I want to make this string like this </p>
  
  <pre><code>[1] "\r\nfundcompanyfee \r\nsalesgrouppayment \r\nmanagementfirmfee \r\ntotalpayment \r\nsubtotalfee \r\nsyntheticfee... sth ... \r\n0.646 0.030 0.030 0.015 1.253....
  </code></pre>
  
  <p>I tried to use gsub function like this</p>
  
  <pre><code> gsub("\r\n\\w\\w.*?fee|payment","\\w\\w",strings)
  </code></pre>
  
  <p>but the result was awful. it makes string like this</p>
  
  <pre><code>ww ww ww ww........ 0.646 0.030 0.030 ....
  </code></pre>
  
  <p>that is it doesn't recognize \w as word.. just translate it to 'w' as it is!</p>
  
  <p>So I need some help to deal with this.
  Thank you for reading.</p>