title: Regex optional group parsing
body: <p>Been fiddling with this for hours...</p>
  
  <p>I'm trying to parse error messages of this form:</p>
  
  <pre><code>[error]  C:\Me\MyPath\myFile.scala:18:22: not found: value getaa
  </code></pre>
  
  <p>I can do this fine with the following regex:</p>
  
  <pre><code>\[(error|warn)\]\s+(.+):(\d+):(?:\d+:)\s+(.+)$
  </code></pre>
  
  <p>Which correctly produces groups:</p>
  
  <pre><code>error
  C:\Me\MyPath\myFile.scala
  18
  not found: value getaa
  </code></pre>
  
  <p>But to make this robust, I need to make the <code>22:</code> part optional (since some versions of the scala compiler don't output column number). In other words, it needs to produce the same groups as above for this string too:</p>
  
  <pre><code>[error]  C:\Me\MyPath\myFile.scala:18: not found: value getaa
  </code></pre>
  
  <p>I've tried putting a question mark after the optional group, but that doesn't work - it messes up the original groups. I assume there's some stuff about lazy vs greedy that I'm not understanding. <a href="https://regex101.com/r/L3JUok/1/" rel="nofollow noreferrer">Here is a working sample</a> on regex101. Thanks for any help.</p>