title: How to extract string before and after match with dynamic values, using 'Powershell' and 'RegEx'
body: <p>I want to extract parts of a text file using PowerShell and regex. 
  The file is built on values starting from "10" and goes on to "50". All values are static except from "50" (can occur many times in a row)
  So far I got this: </p>
  
  <pre><code>Select-String .\sample.txt -pattern '^40[\s][\s][\s][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][\s][0][1]' -context 19,0
  </code></pre>
  
  <p>This matches my value and extracts the previous 19 lines of text, so far so good. Then I need to extract the lines proceeding the match, until the next "10".
  I know that '-context 19,0' will not extract any lines proceeding the match. It is just as far as I got before getting stuck. Any help is appreciated. Here is an example of the file:</p>
  
  <pre><code>10
  20
  21
  22   Value
  23   Value
  24   Value
  25
  26
  27
  28
  29
  30
  31
  32 
  33
  34
  35
  36
  37
  40   1111111111 01      
  50   Value                                                                                                                                             
  50   Value 
  50   Value                                                                                                                                             
  50   Value 
  50   Value                                                                                                                                             
  50   Value 
  50   Value 
  50   Value                                                                                                                                             
  50   Value 
  10
  20
  21
  22   Value
  23   Value
  24   Value
  25
  26
  27
  28
  29
  30
  31
  32 
  33
  34
  35
  36
  37
  40   1111111112 01      
  50   Value                                                                                                                                             
  50   Value 
  50   Value                                                                                                                                             
  50   Value 
  50   Value                                                                                                                                             
  50   Value 
  </code></pre>
  
  <p>The output that i want is this: </p>
  
  <pre><code>    10
      20
      21
      22   Value
      23   Value
      24   Value
      25
      26
      27
      28
      29
      30
      31
      32 
      33
      34
      35
      36
      37
      40   1111111111 01      
      50   Value                                                                                                                                             
      50   Value 
      50   Value                                                                                                                                             
      50   Value 
      50   Value                                                                                                                                             
      50   Value 
      50   Value 
      50   Value                                                                                                                                             
      50   Value 
  </code></pre>