title: Extract last 4-digit number from a series in R using stringr
body: <p>I would like to flatten lists extracted from HTML tables.  A minimal working example is presented below.  The example depends on the <code>stringr</code> package in R.  The first example exhibits the desired behavior.</p>
  
  <pre><code>years &lt;- c("2005-", "2003-")
  unlist(str_extract_all(years,"[[:digit:]]{4}"))
  
  [1] "2005" "2003"
  </code></pre>
  
  <p>The below example produces an undesirable result when I try to match the last 4-digit number in a series of other numbers.</p>
  
  <pre><code>years1 &lt;- c("2005-", "2003-", "1984-1992, 1996-")
  unlist(str_extract_all(years1,"[[:digit:]]{4}$"))
  
  character(0)
  </code></pre>
  
  <p>As I understand the documentation, I should include <code>$</code> at the end of the pattern in order to request the match at the end of the string.  I would prefer to match from the second example the numbers, "2005", "2003", and "1996".</p>