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?

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Custom language module for react-native apps

Modern, password manager friendly login form in Angular Material

AngularJs. Vs. NodeJs. Vs. ReactJs: Which Is The Best Choice in 2021?

How Is JavaScript Contributing To Web App UX?

File Naming Conventions in NestJS

FileName and Indexing

How to make the array go brrr

Fix your Express error handling now

Concerns about “Flux Standard Action” (FSA)

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
none

none

More from Medium

Multithreading In Java

Object Serialization and Deserialization in Java

Java vs JavaScript | Detailed comparison | All-time-dev

Java vs JavaScript

Working with Java Variables

Title image