Expression Help: Highlight Word(s)
Hi all,
i have to modify a setup, which allows the user to highlight one or multiple words by adding “**” before and after. The original setup works by adding “=” ( For example: This is a =Highlight=). On a separate Text Layer, everything outside those two “=” characters is then faded out by an expression selector and a specific font is chosen to generate a colored box behind the marked text (in this example only behing the word “Highlight”). This setup works pretty good so far, but i can not find a way to mark the words to be highlighted with "**" (two characters) instead of one ("="). Anyone any idea how to modify the following code to make this work? I have already tried to add && txt[i+1] == "*" to the if-statement, but that doesn`t seem to work as expected. It kind worked / find`s the right In-Point / Start of the highlighted word, but messes up the letters / doesn`t find the correct Out-Point of the marked word.
Many thanks in advance!
const txt = thisComp.layer(“Master_Text”).text.sourceText.replace(/\n|\r|\u0003/g,””);
var txt_highlight = false;
var count = textIndex;
for (i = 0; i < count; i++) {
if (txt[i] == “=”) {
txt_highlight =! txt_highlight;
count++; i++;
}
}
if (txt_highlight == 1){
0;
}
else{
100;
}

