title: How to get capturing group functionality in Go regular expressions
body: <p>I'm porting a library from Ruby to Go, and have just discovered that regular expressions in Ruby are not compatible with Go (google RE2). It's come to my attention that Ruby &amp; Java (plus other languages use PCRE regular expressions (perl compatible, which supports capturing groups)), so I need to re-write my expressions so that they compile ok in Go.</p>
  
  <p>For example, I have the following regex:</p>
  
  <pre><code>`(?&lt;Year&gt;\d{4})-(?&lt;Month&gt;\d{2})-(?&lt;Day&gt;\d{2})`
  </code></pre>
  
  <p>This should accept input such as:</p>
  
  <pre><code>2001-01-20
  </code></pre>
  
  <p>The capturing groups allow the year, month and day to be captured into variables. To get the value of each group, it's very easy; you just index into the returned matched data with the group name and you get the value back. So, for example to get the year, something like this pseudo code:</p>
  
  <pre><code>m=expression.Match("2001-01-20")
  year = m["Year"]
  </code></pre>
  
  <p>This is a pattern I use a lot in my expressions, so I have a lot of re-writing to do.</p>
  
  <p>So, is there a way to get this kind of functionality in Go regexp; how should I re-write these expressions?</p>