I'm trying to find and replace a word in a string
Example:
let string =
`
Title: Hello World
Authors: Michael Dan
`
I need to find the Hellow World and replace with whatever I want, here is my attempt:
const replace = string.match(new RegExp("Title:" + "(.*)" + "Authors:")).replace("Test")
replace(), you do not need tomatch().string.replace(/(Title:).*(?=\nAuthors:)/gs, '$1Test')can be used here.sflag. Anyway, you need to keep the first and last words.