title: Regex to change the number of spaces in an indent level
body: <p>Let's say you have some lines that look like this</p>
  
  <pre><code>1  int some_function() {
  2    int x = 3;  // Some silly comment
  </code></pre>
  
  <p>And so on. The indentation is done with spaces, and each indent is two spaces.</p>
  
  <p>You want to change each indent to be <em>three</em> spaces. The simple regex</p>
  
  <pre><code>s/ {2}/   /g
  </code></pre>
  
  <p>Doesn't work for you, because that changes some non-indent spaces; in this case it changes the two spaces before <code>// Some silly comment</code> into three spaces, which is not desired. (This gets far worse if there are tables or comments aligned at the back end of the line.)</p>
  
  <p>You can't simply use</p>
  
  <pre><code>/^( {2})+/
  </code></pre>
  
  <p>Because what would you replace it with? I don't know of an easy way to find out how many times a <code>+</code> was matched in a regex, so we have no idea how many altered indents to insert.</p>
  
  <p>You could always go line-by-line and cut off the indents, measure them, build a new indent string, and tack it onto the line, but it would be oh so much simpler if there was a regex.</p>
  
  <p>Is there a regular expression to replace indent levels as described above?</p>