title: Clean string using gsub and multiple conditions
body: <p>I already saw this one, but it is not quite what I need:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/12320595/regex-multiple-pattern-with-singular-replacement">regex multiple pattern with singular replacement</a></li>
  </ul>
  <br />
  <p><strong>Situation:</strong> Using <code>gsub</code>, I want to clean up strings. These are my conditions:</p>
  <ol>
  <li>Keep words only (no digits nor &quot;weird&quot; symbols)</li>
  <li>Keep those words separated with one of (just one) <code>' - _ $ .</code> as one. For example: <code>don't</code>,<code> re-loading</code>, <code>come_home</code>, <code>something$col</code></li>
  <li>keep specific names, such as <code>package::function</code> or <code>package::function()</code></li>
  </ol>
  <p>So, I have the following:</p>
  <ol>
  <li><code>[^A-Za-z]</code></li>
  <li><code>([a-z]+)(-|'|_|$)([a-z]+)</code></li>
  <li><code>([a-z]+(_*)[a-z]+)(::)([a-z]+(_*)[a-z]+)(\(\))*</code></li>
  </ol>
  <br />
  <p><strong>Examples:</strong></p>
  <p>If I have the following:</p>
  <pre><code># Re-loading pkgdown while it's running causes weird behaviour with # the context cache don't
  # Needs to handle NA for desc::desc_get()
  # Update href of toc anchors , use &quot;-&quot; instead &quot;.&quot;
  # Keep something$col or here_you::must_stay
  </code></pre>
  <p>I would like to have</p>
  <pre><code>Re-loading pkgdown while it's running causes weird behaviour with the context cache don't
  Needs to handle NA for desc::desc_get()
  Update href of toc anchors use instead
  Keep something$col or here_you::must_stay
  </code></pre>
  <br />
  <p><strong>Problems:</strong> I have several:</p>
  <p>A. The second expression is not working properly. Right now, it only works with <code>-</code> or <code>'</code></p>
  <p>B. How do I combine all of these in a single <code>gsub</code> in R? I want to do something like <code>gsub(myPatterns, myText)</code>, but don't know how to fix and combine all of this.</p>