title: Java regular expression for filename with one date and optional second date
body: <p>I have files like the following:</p>
  
  <pre><code>Foo_Apr17_bar_May18.csv
  Foo_Mar16.csv
  </code></pre>
  
  <p>The first month will always be 3 letters, and the first year will always directly follow it with 2 digits.
  The second month, if present, will also always be 3 letters, followed by 2 digits for the second year.
  The second month and year may not be present, however.</p>
  
  <p>How can I always capture the first month and year, and capture the second month and year if they are present?</p>
  
  <p>This is not quite cutting it:</p>
  
  <pre><code>^.*_([\w]{3})([\d]{2}).*(([\w]{3})([\d]{2}))?.*.csv
  </code></pre>
  
  <p>Thanks!</p>
  
  <p><strong>NOTE</strong></p>
  
  <p>I am only allowed to pass a single regular expression without multiple matching. The code is not possible to alter. The regex is passed in via a configuration file, as are the field names. The field names are used as map keys.</p>