title: Single Regular Expression to match ranges (1999-2010) or just a single value (2010)?
body: <p>In general, I don't think I've come across a generic solution to this problem. How do you match a string that can be a range, or just a single value?</p>
  
  <p>Say I want to match [complex] dates:</p>
  
  <ul>
  <li>1999 - 2010</li>
  <li>323 BCE - 100 CE</li>
  <li>323 BC</li>
  <li>1995-99</li>
  <li>323 - 322 BC</li>
  </ul>
  
  <p>What is the general regular expression "template" that can parse both of these cases:</p>
  
  <ol>
  <li>The start/end date if it exists</li>
  <li>Otherwise, just a single date</li>
  </ol>
  
  <p>To match "1999 - 2010", you can just do</p>
  
  <pre><code>/(\d+\s*)-(\s*\d+)/ // where $1 and $2 are start and end
  </code></pre>
  
  <p>To match the more complex "323 BCE - 100 CE", you can do</p>
  
  <pre><code>/(\w+\s*\w+)\s*-\s*(\w+\s*\w+)/
  </code></pre>
  
  <p>And to match the simpler "323 BC", you can do</p>
  
  <pre><code>/\w+\s*\w+/
  </code></pre>
  
  <p>But how do you write one expression that first checks for the <em>range</em> (323 BCE - 100 CE), and if that doesn't exist, checks for a single value (323 BC), that can also handle the other examples in the list above?</p>