title: Conditionally replace regex matches in string
body: <p>I am trying to replace certain patterns in a string with different replacement patters.</p>
  
  <p>Example:</p>
  
  <pre><code>string test = "test replacing \"these characters\"";
  </code></pre>
  
  <p>What I want to do is replace all ' ' with '_' and all other non letter or number characters with an empty string.  I have the following regex created and it seems to tokenize correctly, but I am not sure how to (if possible) perform a conditional replace using <code>regex_replace</code>.</p>
  
  <pre><code>string test = "test replacing \"these characters\"";
  regex reg("(\\s+)|(\\W+)");
  </code></pre>
  
  <p>expected result after replace would be:</p>
  
  <pre><code>string result = "test_replacing_these_characters";
  </code></pre>
  
  <p>EDIT:
  I cannot use boost, which is why I left it out of the tags. So please no answer that includes boost. I have to do this with the standard library. It may be that a different regex would accomplish the goal or that I am just stuck doing two passes.</p>
  
  <p>EDIT2:
  I did not remember what characters were included in <code>\w</code> at the time of my original regex, after looking it up I have further simplified the expression. Again the goal is anything matching \s+ should be replaced with '_' and anything matching \W+ should be replaced with empty string.</p>