Last active
November 27, 2018 08:03
-
-
Save chris-sev/fd957d8935a577a6666e85ae9d34f00d to your computer and use it in GitHub Desktop.
Replace All Instances of a Word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. we have a sentence | |
const message = 'This is my store. In my store we store store store.' | |
// 2. replace all store with shop using a regular expression | |
// normally .replace() will only replace the 1st occurrence | |
const newMessage = message.replace(new RegExp('store', 'g'), 'shop'); | |
// 3. output: This is my shop. In my shop we shop shop shop. | |
console.log(newMessage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment