let: string str =
"a=<random text>
a=pattern:<random text (may be fixed length)>
a=<random text>";
Suppose, from above string a=
and pattern
are fixed. There may or may not be \n
after each line.
How to remove a=pattern:<random>
from the str
string?
CodePudding user response:
You could use regex capturing groups. Capture the text before and after the text you want to remove.
let newStr = str.replace(/(a=. (\n)?)(a=pattern:. )((\n)?a=. )/, "$1$4")