I have a text with \n
characters inside and I have an array of phrases I want to highlight in this text by wrapping its segments with tag. The problem is that I can't find this phrases in text if there is a \n
symbol.
I've tried to replace \n
from text, but I need to restore them after highlight.
let text = 'Looking For An Enterprise Test Authoring Platform?\n
Learn More About Gauge\n
Watch our video to learn if Gauge can help you.'
let phrases = ["Authoring Platform? Learn More", "Gauge Watch our video", "can help you"]
const highlight = (phrase) => text.replace(phrase, `<mark style="background: #4CAF50">${phrase}</mark>`)
phrases.map(phrase=> text = highlight(phrase))
Only last phrase will match with text. I'm looking for some way to ignore \n
and match all this phrases. Or maybe there is another way to solve this. I would appreciate any help!