title: Why does this regex named group capture the wrong text?
body: <p>Does someone have some insight  why the named group <code>ref_id</code> in <code>regex1</code> contains <code>Some address: loststreet 4</code> in the capture below?</p>
  
  <p>I want it to be just <code>loststreet 4</code> and I don't understand why it's not. The code below is from an IRB session.</p>
  
  <p>I've considered the encoding of the strings:</p>
  
  <pre><code>str1 = &lt;&lt;eos
  Burp
  FirstName: Al Bundy
  Ref person:
  Some address: loststreet 4
  Some other address: loststreet 4
  Zip code:
  eos
  # =&gt; "Burp\nFirstName: Al Bundy\nRef person:\nSome address: loststreet 4\nSome other address: loststreet 4\nZip code:\n" 
  
  regex1 = /FirstName:\s?(?&lt;name&gt;[^\n]*).*Ref person:\s?(?&lt;ref_id&gt;[^\n]*).*Some other address: (?&lt;other&gt;[^\n]*)/mi
  # =&gt; /FirstName:\s?(?&lt;name&gt;[^\n]*).*Ref person:\s?(?&lt;ref_id&gt;[^\n]*).*Some other address: (?&lt;other&gt;[^\n]*)/mi 
  
  str1.match(regex1)
  # =&gt; #&lt;MatchData "FirstName: Al Bundy\nRef person:\nSome address: loststreet 4\nSome other address: loststreet 4" name:"Al Bundy" ref_id:"Some address: loststreet 4" other:"loststreet 4"&gt; 
  
  str1.encoding
  # =&gt; #&lt;Encoding:UTF-8&gt; 
  
  regex1 = /FirstName:\s?(?&lt;name&gt;[^\n]*).*Ref person:\s?(?&lt;ref_id&gt;[^\n]*).*Some other address: (?&lt;other&gt;[^\n]*)/miu
  # =&gt; /FirstName:\s?(?&lt;name&gt;[^\n]*).*Ref person:\s?(?&lt;ref_id&gt;[^\n]*).*Some other address: (?&lt;other&gt;[^\n]*)/mi 
  
  str1.match(regex1)
  # =&gt; #&lt;MatchData "FirstName: Al Bundy\nRef person:\nSome address: loststreet 4\nSome other address: loststreet 4" name:"Al Bundy" ref_id:"Some address: loststreet 4" other:"loststreet 4"&gt; 
  </code></pre>