title: How do I perform a simple regular expression match in bash?
body: <p>I'm trying to match the number that's in the beginning of a string</p>
  
  <blockquote>
    <p>452MATCHME</p>
  </blockquote>
  
  <p>With this simple regex</p>
  
  <pre><code>/^\d*/
  </code></pre>
  
  <p>And I want this result, saved in a variable</p>
  
  <blockquote>
    <p>452</p>
  </blockquote>
  
  <p>But I can't find a way to get the result of the operation. I've read <a href="http://www.linuxjournal.com/content/bash-regular-expressions" rel="nofollow">this tutorial</a>, but it describes an array <code>BASH_REMATCH</code> where all match results of <code>=~</code> operations are stored. That array doesn't exist in my case though, for some reason. I'm using bash version 4.2.10(1).</p>
  
  <p>The only other option I can think of is <code>grep</code>, but that can only output which lines matched the regex, as far as I know.</p>
  
  <p>How can I achieve my result?</p>