Activity › Forums › Adobe After Effects Expressions › Expression to select and affect specific characters in a text
-
Expression to select and affect specific characters in a text
Posted by Enrique Rovira on June 2, 2015 at 10:23 amOk so I have been trying to find this all over the internet but no luck so far.
I am trying to create an expression in a text layer so that a specific character is found in the text, like this bullet point: • (alt+8), a different colour is applied.
Any ideas?
Thx, E
Jan Vork replied 4 years, 2 months ago 5 Members · 14 Replies -
14 Replies
-
Dan Ebberts
June 2, 2015 at 4:46 pmTry this.
Add a Fill Color Animator and set the color for the special character.
Add an Expression Selector.
Delete the Range Selector.
Replace the Amount expression in the Expression Selector with this:
myChar = “•”;
if (text.sourceText[textIndex-1] == myChar) 100 else 0Dan
-
Enrique Rovira
June 3, 2015 at 8:28 amActually I came across a problem, for some reason it selects the correct character on the first line but then selects and modifies the colour of the second character on the second line, the third character on the third line, and so on. Of course the bullet point is always the first character on each line.
-
Enrique Rovira
June 3, 2015 at 8:53 amWe tried moving things around as below, but to no use!
myChar = text.sourceText.value[textIndex-1];
if (myChar === "•") { 100 } else { 0 }; -
Enrique Rovira
June 3, 2015 at 9:07 amWe also tried this expression, from another of your posts actually.
But we get to the exact same problem, on each line will select a further character… If I put everything in one single line it works fine though.
c = text.sourceText.value[textIndex-1];
if (/^\•/i.test(c)) 100 else 0 -
Dan Ebberts
June 3, 2015 at 4:02 pmTry it this way:
txt = text.sourceText.replace(/\r?\n|\r/g,'');
myChar = "•";
if (txt[textIndex-1] == myChar) 100 else 0
Dan
-
Enrique Rovira
June 3, 2015 at 4:23 pmOk now THAT worked perfect! I’m tinkering with it now but it seems all is fine.
Thanks!
-
Nathan Clark
February 11, 2019 at 7:58 amHi there, I was hoping to get this setup working today but sadly it fails… is this because of the new expression engine? would it be possible to get some guidance on getting this to work in AE 16.0.1? Thanks in advance 🙂
-
Dan Ebberts
February 11, 2019 at 2:10 pmThis should work:
txt = text.sourceText.replace(/\r?\n|\r/g,”);
myChar = “•”;
txt[textIndex-1] == myChar ? 100 : 0Dan
-
Nathan Clark
February 11, 2019 at 10:28 pmIndeed, it works beautifully. Thanks for taking the time to share your knowledge, it is deeply appreciated.
Reply to this Discussion! Login or Sign Up