title: Is there a shorter way to extract a date from a string?
body: <p>I wrote code to extract the date from a given string. Given </p>
  
  <pre><code>  &gt; "Date: 2012-07-29, 12:59AM PDT"
  </code></pre>
  
  <p>it extracts</p>
  
  <pre><code>  &gt; "2012-07-29" 
  </code></pre>
  
  <p>The problem is my code looks lengthy and cumbersome to read. I was wondering if was a more elegant way of doing this. </p>
  
  <pre><code>  raw_date = "Date: 2012-07-29, 12:59AM PDT"
  
    #extract the string from raw date
    index = regexpr("[0-9]{4}-[0-9]{2}-[0-9]{2}", raw_date) #returns 'start' and 'end' to be used in substring
  
    start = index #start represents the character position 's'. start+1 represents '='
    end = attr(index, "match.length")+start-1
    date = substr(raw_date,start,end); date
  </code></pre>