Node.js is basically the same as Javascript, except that it runs on the server.
Back to your question, below is the snippet to find all occurrence of .ChildBucket
, and replace them by .ParentBucket.ChildBucket
.
const original = `
# dummy text 1
webApplication.ChildBucketOne
# dummy text 2
webApplication.ChildBucketTwo
# dummy text 3
`
console.log('--- Original ---')
console.log(original)
const replaced = original.replace(/\.ChildBucket/g, '.ParentBucket.ChildBucket')
console.log('--- Replaced ---')
console.log(replaced)
Explanation
You see that I use regular expression (i.e. /\.ChildBucket/g
) instead of a string because the replace function will only replace the first occurrence of the matching string by default. Using regular expression with the g
modifier will turn it into the global match, which replaces all the occurrence.
Output
--- Original ---
# dummy text 1
webApplication.ChildBucketOne
# dummy text 2
webApplication.ChildBucketTwo
# dummy text 3
--- Replaced ---
# dummy text 1
webApplication.ParentBucket.ChildBucketOne
# dummy text 2
webApplication.ParentBucket.ChildBucketTwo
# dummy text 3