title: RegExp object won't execute more than once, why?
body: <p>I stored a RegExp object in a variable and used it for mapping an array of strings into an array of objects (parsed e-mail recipients), but it doesn't work, as if a RegExp object couldn't run its <code>.exec()</code> method more than once.</p>
  <p>However, if I use a regular expression literal instead of the stored object, it works as intended.</p>
  <p><strong>I cannot understand the reason behind this behavior. Is it expected, or could it be a bug?</strong></p>
  <p>The code:</p>
  <pre><code>const pattern = /^\s*(?&lt;name&gt;\w.*?)?\W+(?&lt;address&gt;[a-zA-Z\d._-]+@[a-zA-Z\d._-]+\.[a-zA-Z\d_-]+)\W*$/gi;
  const input = &quot;John Doe jdoe@acme.com; Ronald Roe &lt;rroe@acme.com&gt;&quot;;
  const splitValues = input.split(/[\r\n,;]+/).map(s =&gt; s.trim()).filter(s =&gt; !!s);
  const matchGroups1 = splitValues.map(s =&gt; pattern.exec(s));
  console.log('Using pattern RegExp object:', JSON.stringify(matchGroups1, null, 2));
  const matchGroups2 = splitValues.map(s =&gt; /^\s*(?&lt;name&gt;\w.*?)?\W+(?&lt;address&gt;[a-zA-Z\d._-]+@[a-zA-Z\d._-]+\.[a-zA-Z\d_-]+)\W*$/gi.exec(s));
  console.log('Using literal regular expression:', JSON.stringify(matchGroups2, null, 2));
  </code></pre>
  <p>The output:</p>
  <pre><code>[LOG]: &quot;Using pattern RegExp object:&quot;,  &quot;[
    [
      &quot;John Doe jdoe@acme.com&quot;,
      &quot;John Doe&quot;,
      &quot;jdoe@acme.com&quot;
    ],
    null
  ]&quot; 
  [LOG]: &quot;Using literal regular expression:&quot;,  &quot;[
    [
      &quot;John Doe jdoe@acme.com&quot;,
      &quot;John Doe&quot;,
      &quot;jdoe@acme.com&quot;
    ],
    [
      &quot;Ronald Roe &lt;rroe@acme.com&gt;&quot;,
      &quot;Ronald Roe&quot;,
      &quot;rroe@acme.com&quot;
    ]
  ]&quot; 
  </code></pre>
  <h1><a href="https://www.typescriptlang.org/pt/play?#code/MYewdgzgLgBADgQylApgJzDAvDA9APQB0IAqACgH4AeMBAWxQD5CB3AOhIoEoLCB1ANSUqCACai0KCBEYBtBAFoAXgEEFALUKi2AfQUBdAQAF5ytZu17DhNqdUatVgV34kAJLgDmASwDcAKFBIWG8wOABXWBwAIgApEAALTAAREBQYACtRNKMEYAY2UDpfGAAlcAQAG1EytJgqNDQcvIKixmiAoOgYCDhK7ygANSrwqWwYUIioNl7+qDJcWUI0QjAAGl9DXC42OgQ4MghsRh62KDRvOjIuHYAzb0rUNEPjmABCN4guTvBuvahgAkAOJNcJwCAARnGswGw0qowgu32LywJ0QyHQYDYKAAHihgIcbj9ICBKig2JUQJ4yAByACqEFCnngSCemFKKE8AFEcXAYCAAEYZfFQABcNLWMFiAGUAPIAORm5yZ3luAE8yP9ASCQGDIZKwOFKpVJQAmImBX6wLXA0Hg03QvqwkZSJEHI6ovBEUjCWgMZjsTg8fhCahiCRSGR2cxaXQGYzRhyWeM2RMWJwuPjuLzebF4glfb6WklkilU2kMpkwOboKowSSeI0INAwXFwSTSbzgcWSmUKpUXMA+dWapDau0QU0Go0mmDm75AA" rel="nofollow noreferrer">test in TypeScript playground</a></h1>