ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to select and affect specific characters in a text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Enrique Rovira
Expression to select and affect specific characters in a text
on Jun 2, 2015 at 10:23:41 am

Ok 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


Return to posts index

Dan Ebberts
Re: Expression to select and affect specific characters in a text
on Jun 2, 2015 at 4:46:22 pm

Try 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 0


Dan



Return to posts index

Enrique Rovira
Re: Expression to select and affect specific characters in a text
on Jun 2, 2015 at 5:51:15 pm

Thanks Dan, worked beautifully!


Return to posts index


Enrique Rovira
Re: Expression to select and affect specific characters in a text
on Jun 3, 2015 at 8:28:09 am

Actually 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.


Return to posts index

Enrique Rovira
Re: Expression to select and affect specific characters in a text
on Jun 3, 2015 at 8:53:07 am

We tried moving things around as below, but to no use!

myChar = text.sourceText.value[textIndex-1];
if (myChar === "•") { 100 } else { 0 };


Return to posts index

Enrique Rovira
Re: Expression to select and affect specific characters in a text
on Jun 3, 2015 at 9:07:04 am

We 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


Return to posts index



Dan Ebberts
Re: Expression to select and affect specific characters in a text
on Jun 3, 2015 at 4:02:42 pm

Try it this way:


txt = text.sourceText.replace(/\r?\n|\r/g,'');
myChar = "•";
if (txt[textIndex-1] == myChar) 100 else 0



Dan



Return to posts index

Enrique Rovira
Re: Expression to select and affect specific characters in a text
on Jun 3, 2015 at 4:23:27 pm

Ok now THAT worked perfect! I'm tinkering with it now but it seems all is fine.

Thanks!


Return to posts index

Nathan Clark
Re: Expression to select and affect specific characters in a text
on Feb 11, 2019 at 7:58:45 am

Hi 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 :)


Return to posts index


Dan Ebberts
Re: Expression to select and affect specific characters in a text
on Feb 11, 2019 at 2:10:59 pm

This should work:

txt = text.sourceText.replace(/\r?\n|\r/g,'');
myChar = "•";
txt[textIndex-1] == myChar ? 100 : 0


Dan



Return to posts index

Nathan Clark
Re: Expression to select and affect specific characters in a text
on Feb 11, 2019 at 10:28:20 pm

Indeed, it works beautifully. Thanks for taking the time to share your knowledge, it is deeply appreciated.


Return to posts index

Balazs Kun
Re: Expression to select and affect specific characters in a text
on Feb 18, 2019 at 11:01:06 am

Hello!

It works fine and thanks for sharing this code.

How could I select multiple characters? For example I want to select all "a" and "e" letters from a string.
I tried use an array but didn't work.


Thanks!


Return to posts index


Dan Ebberts
Re: Expression to select and affect specific characters in a text
on Feb 18, 2019 at 7:15:35 pm

Something like this should work:


txt = text.sourceText.replace(/\r?\n|\r/g,'');
myChars = "ae";
result = 0;
for (i = 0; i < myChars.length; i++){
if (txt[textIndex-1] == myChars[i]){
result = 100;
break;
}
}
result


Dan



Return to posts index

Balazs Kun
Re: Expression to select and affect specific characters in a text
on Feb 19, 2019 at 8:02:22 am

Perfect.
Thank You!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]