title: regex replacement that adds text
body: <p>I'm trying to do link rewriting in my mobile application (written in ruby). I would like it to be able to accomplish both of these rewrites with a single regular expression:</p>
  
  <pre><code>m.example.com -&gt; www.example.com
  m.subd.example.com -&gt; subd.example.com
  </code></pre>
  
  <p>The closest I've gotten replacing this:</p>
  
  <pre><code>m\.([a-z\.]*)example\.com
  </code></pre>
  
  <p>with this:</p>
  
  <pre><code>$1example.com
  </code></pre>
  
  <p>This works for the m.subd.example.com but it fails for m.example.com because of my "www." exception.</p>
  
  <p>I do this A LOT so i'd like it to be very fast, which is why I am trying to avoid using any code, just a single regex. Is it possible? Is there a fancy feature of regex that I don't know about?</p>