ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to detect hashtag and @ with Expressions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jeremy Garcini
How to detect hashtag and @ with Expressions
on Jun 30, 2020 at 7:16:09 am
Last Edited By Jeremy Garcini on Jun 30, 2020 at 7:45:34 am

Hi,
I was wondering if it's possible to detect a hashtag or @ and automatically change the color?

I'm a javascript developer and I found a way to detect hashtag and @ but I don't know how to change the color then...

Look at this picture:


Thank you,
Jeremy

string = value;
string.replace(/(^|s)(#[a-zd-]+)/ig, "$1<color>$2</color>")


Return to posts index

Scott McGee
Re: How to detect hashtag and @ with Expressions
on Jun 30, 2020 at 8:32:22 am

Someone might reply with a more modern method if it exists.

But if you put a fill color using the Animate button to the right when you drop down the text layer, then add an expression selector onto it. Something like this will work

words = text.sourceText.replace(/^\s+/, "").split(/\s+/);
if (words[textIndex-1].indexOf ("#") >-1) 100 else 0


Return to posts index

Jeremy Garcini
Re: How to detect hashtag and @ with Expressions
on Jun 30, 2020 at 9:01:18 am

Thank you, it works well!
Different subject but do you know if there's a way to detect a specific sentence then also change the color?

Example:
"Welcome on [start:color]Creativecow.net Jeremy[end:color], I hope you're enjoying your day."

Thank you


Return to posts index


Scott McGee
Re: How to detect hashtag and @ with Expressions
on Jun 30, 2020 at 4:33:05 pm

Stealing this one from Dan Ebberts in another post. All you need to do is put a "[" at the front of the string and "]" at the end. Anything inbetween will be filled.

Put this into your sourceText

str = text.sourceText;
zws = "\u200b";
res1 = str.replace(/\[/g, zws);
res2 = res1.replace(/\]/g, zws);

and this into the expression selector, make sure to change Based on to Characters

txt = text.sourceText;
zws = "\u200b";
idx = 1;
i = 0;
n = 0;
while (idx < textIndex){
if (txt.value[i] == "\r"){
i++;
continue;
}
if (txt.value[i] == zws) n++;
i++;
idx++;
}
n%2 ? 100 : 0


Return to posts index

Jeremy Garcini
Re: How to detect hashtag and @ with Expressions
on Jul 1, 2020 at 6:01:51 am

Thank you! Everything works very well!


Return to posts index

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