Replace every matching word with a new value.

Replacing Patterns

replace_pattern.js
const source = "red blue red";
const updated = source.replace(/red/g, "green");

console.log("source=" + source);
console.log("updated=" + updated);
replace-pattern `replace` can use a regular expression. The `g` flag repeats the replacement for every match instead of only the first match.