title: Using string.prototype.replace with a regexp and a function
body: <p>The following returns 'entiy'. I want it to return 'entity'. How can I achieve this?</p>
  
  <pre><code>'entities '.replace(/\w(ies)(?:[\W|$|_])+/g, 'y');
  </code></pre>