title: What is the purpose of the 'y' sticky pattern modifier in JavaScript RegExps?
body: <p>MDN introduced the 'y' sticky flag for JavaScript RegExp. Here is a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp" rel="nofollow noreferrer">documentation excerpt</a>:</p>
  <blockquote>
  <p><strong>y</strong></p>
  <p>sticky; matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes).</p>
  </blockquote>
  <p>There's also an example:</p>
  <pre><code>var text = 'First line\nSecond line';
  var regex = /(\S+) line\n?/y;
  
  var match = regex.exec(text);
  console.log(match[1]);        // prints 'First'
  console.log(regex.lastIndex); // prints '11'
  
  var match2 = regex.exec(text);
  console.log(match2[1]);       // prints 'Second'
  console.log(regex.lastIndex); // prints '22'
  
  var match3 = regex.exec(text);
  console.log(match3 === null); // prints 'true'
  </code></pre>
  <p>But there isn't actually any difference between the usage of the <strong>g</strong> global flag in this case:</p>
  <pre><code>var text = 'First line\nSecond line';
  var regex = /(\S+) line\n?/g;
  
  var match = regex.exec(text);
  console.log(match[1]);        // prints 'First'
  console.log(regex.lastIndex); // prints '11'
  
  var match2 = regex.exec(text);
  console.log(match2[1]);       // prints 'Second'
  console.log(regex.lastIndex); // prints '22'
  
  var match3 = regex.exec(text);
  console.log(match3 === null); // prints 'true'
  </code></pre>
  <p>Same output. So I guess there might be something else regarding the 'y' flag and it seems that MDN's example isn't a real use-case for this modifier, as it seems to just work as a replacement for the 'g' global modifier here.</p>
  <p>So, what could be a <em>real use-case</em> for this experimental 'y' sticky flag? What's its purpose in &quot;matching only from the RegExp.lastIndex property&quot; and what makes it differ from 'g' when used with <code>RegExp.prototype.exec</code>?</p>
  <p>Thanks for the attention.</p>