Highlight certain words in Text

@jonatandor35

Thx J.D.!
I think i have to take a closer look to this.

I could convert it to my own code-version (even if i do not understand all steps).
Thanks, for your help!

Can you explain a little this code-line…

new RegExp(toHighlight, "g");

Is it the only way, how to solve with your code-structure?

let toHighlight = "and";
let regex = new RegExp(toHighlight, "g");
$w("#text1").html = $w("#text1").html.replace(regex, `<mark>${toHighlight}</mark>`);

Or is it also possible to insert/edit/inject it directly here…

let res2 = str.replace(/DIRECT-INJECTION-HERE/gi, `<mark>${searchWord}</mark>`);

My own solution (with your help), which now works like it should, looks like this…

export function button66_click(event) {
 //let searchWord = $w('#input1').value
 let str = $w('#text1').text 
 let toHighlight = $w('#input1').value
 let regex = new RegExp(toHighlight, "g");
 let result = str.replace(regex, `<mark>${toHighlight}</mark>`);       
    $w("#text1").html=result
}

The line i do not understand is this one…

let regex = new RegExp(toHighlight, "g");

Where i can get information for this?

And here the result…

https://russian-dima.wixsite.com/meinewebsite/highlight-mark-some-text

THX!