title: Add underscore before every upper case letter followed by lower case
body: <p>I'm trying to add underscore before every capital letter followed by lower case. Here is the example:</p>
  
  <pre><code>cases &lt;- c("XrefAcctnoAcctID", "NewXref1AcctID", "NewXref2AcctID", "ClientNo")
  </code></pre>
  
  <p>I have this:</p>
  
  <pre><code>[1] "XrefAcctnoAcctID" "NewXref1AcctID"  
  [3] "NewXref2AcctID"   "ClientNo"     
  </code></pre>
  
  <p>And I want to have this:</p>
  
  <pre><code>"xref_acctno_acct_id" 
  "new_xref1_acct_id"   
  "new_xref2_acct_id"    
  "client_no" 
  </code></pre>
  
  <p>I'm able to go this far:</p>
  
  <pre><code>&gt; tolower(gsub("([a-z])([A-Z])", "\\1_\\2", cases))
  [1] "xref_acctno_acct_id" "new_xref1acct_id"   
  [3] "new_xref2acct_id"    "client_no" 
  </code></pre>
  
  <p>But <code>"new_xref1acct_id"</code> <code>"new_xref2acct_id"</code> does not reflect what I want.</p>