Hi Filip and Yoan,
I was looking through your thread because I need something quite similar to what you have done but a little different. Let me explain: I need to create a .mogrt for my colleagues where they can highlight multiple words in a text. And the idea is to have a text input where they write their text and another text input where they write the words they want to highlight. Here you can see that I succeed to highlight one word, but I can’t figure out how to highlight multiple words.
here is the expression I use to highlight one word:
txt=thisComp.layer(“Highlight”).text.sourceText;
words = txt.split(/\s/);
RE = new RegExp(words,”g”);
hl=text.sourceText.replace(RE, function($0) {
return ‘~’.repeat($0.length);
});
if(hl.charAt(textIndex-1) == ‘~’) { 100 } else { 0 };
I found some code on workbench youtube channel. I know I need a loop
for (i=0, i<words.length, i++){}
But since I am still no master in expression, I don’t know how to write it down. So if one of you hase the answer, it would be great.
Thank you