Hi Ben,
try the following on your expression selector, but based on words (which is more efficient than looping over each char):
const wrapChars = "**"; // Insert your desired wrap character(s)
const L = thisComp.layer("Master_Text");
const controlText = L.text.sourceText.value;
const currentWord = controlText.split(/\s+/)[textIndex - 1];
const escapedWrapChars = wrapChars.replace(/./g, "\\$&");
const regex = new RegExp(^${escapedWrapChars}([^${escapedWrapChars}]*)${escapedWrapChars}$);
regex.test(currentWord) ? 0 : 100;
You can change the wrapChars to any character(s) if you want to reuse the expression for other setups.
Make sure to remove all instances of your wrapChars on your display layer’s source text using something like this:
thisComp.layer("Master_Text").text.sourceText.value.replaceAll("**", "");
But I assume you already have something like that in place 🙂