title: How to match a block of text with C# Regex
body: <p>I have a text file with hundreds of lines that follow this pattern:</p>
  
  <pre><code>[Part 1.SubPart 2.A 1]
  Variable=value
  (...)
  LastVariable1=value
  [Part 1.SubPart 2.B 2]
  Variable=value
  (...)
  LastVariable2=value
  [Part 1.SubPart 2.C 3]
  Variable=value
  (...)
  LastVariable3=value
  [Part 1.SubPart 3.A 1]
  (...)
  </code></pre>
  
  <p>I need to extract each block that starts with <strong>[Part...A *]</strong> and ends before the next "A" block starts. </p>
  
  <p>The very last variable "LastVariable3" has a constant name in all the Parts and can be ignored for my purposes.</p>
  
  <p>I've tried using the following expressions based on other posts here, but they are not working.</p>
  
  <pre><code>var pattern = new Regex(@"\[Part.*A..\])(.*)(^LastVariable3)",RegexOptions.Singleline);
  
  var pattern = new Regex(@"\[Part.*A..\])(.|\n)*(^LastVariable3)",RegexOptions.Singleline);
  </code></pre>
  
  <p>...they always match all the Part blocks in the WHOLE file at once instead of one at a time.</p>
  
  <p>I've also tried   <code>(\[Part.*A..\]\n)(.*(\n)){"number of lines"}</code> but the number of variables are not constant so this won't work.</p>
  
  <p>Hope this made sense!  Any ideas on what I'm doing wrong? I'm new to Regex.</p>