title: R regular expressions: unexpected behavior of "[:digit:]"
body: <p>I'd like to extract elements beginning with digits from a character vector but there's something about POSIX regular expression syntax that I don't understand.</p>
  
  <p>I would think that </p>
  
  <pre><code>vec &lt;- c("012 foo", "305 bar", "other", "notIt 7")
  grep(pattern="[:digit:]", x=vec)
  </code></pre>
  
  <p>would return <code>1 2 4</code> since they are the four elements that have digits somewhere in them. But in fact it returns <code>3 4</code>.</p>
  
  <p>Likewise <code>grep(pattern="^0", x=vec)</code> returns <code>1</code> as I would expect because element 1 starts with a zero. However <code>grep(pattern="^[:digit:]", x=vec)</code> returns <code>integer(0)</code> whereas I would expect it to return <code>1 2</code> since those are the elements that start with digits.</p>
  
  <p>How am I misunderstanding the syntax?</p>