title: Python regex match across multiple lines
body: <p>I am trying to match a regex pattern across multiple lines. The pattern begins and ends with a substring, both of which must be at the beginning of a line. I can match across lines, but I can't seem to specify that the end pattern must also be at the beginning of a line.</p>
  
  <p>Example string:</p>
  
  <pre><code>Example=N      ; Comment Line One error=
  
  ; Comment Line Two.
  
  Desired=
  </code></pre>
  
  <p>I am trying to match from <code>Example=</code> up to <code>Desired=</code>. This will work if <code>error=</code> is not in the string. However, when it is present I match <code>Example=N      ; Comment Line One error=</code></p>
  
  <pre><code>config_value = 'Example'
  pattern = '^{}=(.*?)([A-Za-z]=)'.format(config_value)
  match = re.search(pattern, string, re.M | re.DOTALL)
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>config_value = 'Example'
  pattern = '^{}=(.*?)(^[A-Za-z]=)'.format(config_value)
  match = re.search(pattern, string, re.M | re.DOTALL)
  </code></pre>