title: Groovy Regular Expression Include Lines Around
body: <p>How can I use regular expressions to match a pattern and return the lines around it in Groovy?</p>
  
  <p>For example, if I have the following text:</p>
  
  <pre class="lang-none prettyprint-override"><code>    Filesystem           1K-blocks      Used Available Use% Mounted on
      /dev/sda1              4185956   1206996   2762888  31% /
      /dev/sda11            30679784  28324040    772140  98% /extra
      &lt;..lines omitted..&gt;
      fas3050c-1-2.b:/vol/canis
                            10485760   6599936   3885824  63% /nfs/data_d2/dog_data
      fas6070-1-1.b:/vol/felis
                           314572800  54889600 259683200  18% /nfs/DATA-1/cat_data
  
  We want the available disk space in KB, for /nfs/data remote
  disk partitions, which is "3885824" and "259683200" in the sample
  above. Note that partitions that start out with "/nfs/data" may be
  either upper or lower case. Capture the partition name for debugging.
  
  Capture the space available in KB as the number before the
  percentage number (digits followed by '%'). The pattern match
  is relying on there being just one instance of a numeric
  percentage (\d+%) occurring in the each usable output line.
  </code></pre>
  
  <p>I want is to match the pattern <code>We want the available</code> as well as the 5 lines above and below it, to give the following output: </p>
  
  <pre class="lang-none prettyprint-override"><code>fas3050c-1-2.b:/vol/canis
                        10485760   6599936   3885824  63% /nfs/data_d2/dog_data
  fas6070-1-1.b:/vol/felis
                       314572800  54889600 259683200  18% /nfs/DATA-1/cat_data
  
  We want the available disk space in KB, for /nfs/data remote
  disk partitions, which is "3885824" and "259683200" in the sample
  above. Note that partitions that start out with "/nfs/data" may be
  either upper or lower case. Capture the partition name for debugging.
  
  Capture the space available in KB as the number before the
  </code></pre>