Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to detect hashtag and @ with Expressions

  • How to detect hashtag and @ with Expressions

    Posted by Jeremy Garcini on June 30, 2020 at 7:16 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-z\d-]+)/ig, "$1$2")

    Jeremy Garcini replied 6 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Scott Mcgee

    June 30, 2020 at 8:32 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

  • Jeremy Garcini

    June 30, 2020 at 9:01 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

  • Scott Mcgee

    June 30, 2020 at 4:33 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

  • Jeremy Garcini

    July 1, 2020 at 6:01 am

    Thank you! Everything works very well!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy