title: Optional element in regex in java
body: <p>I have this pattern:</p>
  
  <pre><code>"^([\\d.]+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] \"(.+?)\" (\\d{3}) (\\d+|\\S+)"
  </code></pre>
  
  <p>That I use it on the following apache access log entry:</p>
  
  <pre>
  127.0.0.1 - - [16/Jul/2011:20:29:14 +0100] "GET /TestWebPages/MScAIS-SEWN-Search-Optimisation.html HTTP/1.1" 200 5569
  </pre>
  
  <p>Sometime after the 7th element I might or might not have something. E.g.</p>
  
  <pre>
  127.0.0.1 - - [16/Jul/2011:20:29:14 +0100] "GET /TestWebPages/MScAIS-SEWN-Search-Optimisation.html HTTP/1.1" 200 5569 –
  </pre>
  
  <p>Sometimes I have the <code>-</code> at the end and sometime it just doesn’t exists.</p>
  
  <p>How can add this to my pattern? I tried using <code>(\\S{0})</code> but it did not work!</p>