title: Extract a regular expression match
body: <p>I'm trying to extract a number from a string.</p>
  
  <p>And do something like <code>[0-9]+</code> on the string <code>"aaa12xxx"</code> and get <code>"12"</code>.</p>
  
  <p>I thought it would be something like:</p>
  
  <pre><code>&gt; grep("[0-9]+", "aaa12xxx", value=TRUE)
  [1] "aaa12xxx"
  </code></pre>
  
  <p>And then I figured... </p>
  
  <pre><code>&gt; sub("[0-9]+", "\\1", "aaa12xxx")
  [1] "aaaxxx"
  </code></pre>
  
  <p>But I got some form of response doing:</p>
  
  <pre><code>&gt; sub("[0-9]+", "ARGH!", "aaa12xxx")
  [1] "aaaARGH!xxx"
  </code></pre>
  
  <p>There's a small detail I'm missing.</p>