Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Isolating a string of text (within a larger paragraph)

  • Isolating a string of text (within a larger paragraph)

    Posted by Paul Ducco on November 2, 2022 at 6:06 am

    Hi all, I’m trying to

    I’m guessing regex is useful here and have been experimenting and trying to “cobble” a solution together.

    Wondering if anyone can get me started and or well on the way to an implementable solution.

    In the broader paragraph I’m searching for text that begins with an @ symbol and them the following letters, until the next word/space break.
    (Current regex = /@[a-zA-Z]+\w/gi)

    I’d then like to be able to style that text with a different colour…which I figure I can either do with ‘style’ or converting the regex output to control a Text Animator.

    Hope the above makes sense. Appreciate the input. Thanks in advance.

    Paul Ducco replied 3 years, 6 months ago 4 Members · 8 Replies
  • 8 Replies
  • Filip Vandueren

    November 2, 2022 at 9:16 am

    Hi Paul,

    you’ll have to do it with a text-animator, style can only be set for the entire text-layer at a time.

    Add a text-animator that for example sets the fill to red.

    add an expression selector, change it to “based on words” and give the amount this expression:

    words = text.sourceText.value.split(/[\s\3]+/);

    i = textIndex-1;

    words[i].match(/^@.*/gi) ? value : [0,0,0];

  • Dan Ebberts

    November 2, 2022 at 4:43 pm

    Hey Filip,

    Nice! What does the \3 do?

  • Filip Vandueren

    November 2, 2022 at 6:06 pm

    When you type a shift-enter in after effects text layers, for a soft line break, that is the character AE uses.

    But regex doesn’t see it as a white space or linebreak character so we need to add it explicitly.

    \3 seems to work as shorthand for \u0003 = Unicode character “end of text”

  • Paul Ducco

    November 2, 2022 at 8:27 pm

    Nice. Thank you @Filip.

    Will investigate further. Seems I was massively overcomplicating it.

    Cheers again

  • Paul Ducco

    November 2, 2022 at 8:34 pm

    I get “textIndex is not defined”.
    I noticed this in a tutorial I was following along with and figured it was some additional code reference they wasn’t relevant to my install.

    What have I missed?

  • Paul Ducco

    November 2, 2022 at 8:36 pm

    oooooooofffff, and I’m learning again…never noticed the ability to apply an expressions elector for an Animator.

    Thanks again.

  • Julian Chojnacki

    November 3, 2022 at 4:47 am

    Hi Paul,

    I’m not sure if this is exactly what you’re looking for, but I hope this helps (as an addition/alternative to Filip‘s approach)

    https://www.youtube.com/watch?v=wgiaNEQit3g

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Paul Ducco

    November 3, 2022 at 6:53 am

    Excellent addition and resource for others coming along Julian. Thanks for chiming in.

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