Java String.replace vs Javascript String.prototype.replace

const p = 'The quick brown fox jumps over the lazy Dog*. If the Dog* reacted, was it really lazy?';const regex = /Dog*/g;
console.log(p.replaceAll(regex, 'monkey'));
Output-1: The quick brown fox jumps over the lazy monkey*. If the monkey* reacted, was it really lazy?const regexWithEscapedAserisk = /Dog\*/ig;
console.log(p.replaceAll(regex1, 'monkey'));
Output-2: The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store