Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If Else When Source Text Contains String

  • If Else When Source Text Contains String

    Posted by Sean Walkup on April 12, 2022 at 12:37 pm

    I am building a .mogrt with a paragraph that is all caps and has very tight line spacing. It works great until a user types the letter “Q”, then the descender overlaps the line beneath it. No problem I think to myself, I will just create an if/else that recognizes when the source text contains a “Q” and increase the line spacing. How hard could that be? Two hours later I am stumped.

    I added a Line Spacing animator to the text layer, searched the internet, and learned that there was such a thing as Regular Expressions, broke my brain trying to quickly understand them, and hoped something like this would work. Obviously, it did not.

    var txt = text.sourceText;

    var findQ = txt.test(“q”);

    if(findQ == true) {[value[0], 20]} else {[value[0], 0]}

     

    I am hoping one of you can see through my mistake and offer up an answer cause my brain hurts.

    Thanks in advance.

     

    Sean Walkup replied 4 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Filip Vandueren

    April 12, 2022 at 1:35 pm

    Hi Sean, you can do it without a regex like this:

    var txt = text.sourceText.value;
    var findQ = txt.includes("q");

    note that it doesn’t return true for Q, only lowercase q.

    If you want to do it with a regex test, you have to create the regular expression, and run the .test() method on the regex, not on a string, like this:

    var txt = text.sourceText.value;
    var regexQ = /q/i; // the i makes it case-insensitive: this will match a q or a Q
    var findQ = regexQ.test(txt);

  • Sean Walkup

    April 12, 2022 at 2:26 pm

    Filip, Thank you thank you thank you!!!!!!! I really appreciate it. It works like a charm. Amazing.

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