title: JS regex to split by line
body: <p>How do you split a long piece of text into separate lines? Why does this return <em>line1</em> twice?</p>
  
  <pre><code>/^(.*?)$/mg.exec('line1\r\nline2\r\n');
  </code></pre>
  
  <blockquote>
    <p>["line1", "line1"]</p>
  </blockquote>
  
  <p>I turned on the multi-line modifier to make <code>^</code> and <code>$</code> match beginning and end of lines.  I also turned on the global modifier to capture <em>all</em> lines.</p>
  
  <p>I wish to use a regex split and not <code>String.split</code> because I'll be dealing with both Linux <code>\n</code> and Windows <code>\r\n</code> line endings. </p>