Let's say we have a string:
"The quick brown fox jumps over the lazy dog"
You search within that string for "ove ver".
The result should be that the word "over" is highlighted.
My code so far:
'The quick brown fox jumps over the lazy dog'
.replace(/ove|ver/g, s => s.replace(/\w/g, '<mark>$&</mark>'))
The result should be similar to this demo on regex101.
EDIT: Searching for "o" shouldn't highlight the string till the next word boundary. Searching for "o" should result in: "The quick br<mark>o</mark>wn f<mark>o</mark>x jumps <mark>o</mark>ver the lazy d<mark>o</mark>g"