Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change fill color of text only if it is a URL, otherwise keep original fill

  • Change fill color of text only if it is a URL, otherwise keep original fill

    Posted by Andrew Brinkmann on January 30, 2022 at 1:35 pm

    Hi all, I’m wondering if there’s a way to use an expression selector and possibly regular expressions to give only URL’s in a text layer a particular fill color and leave the rest of the characters in the text layer the original fill color. What I am trying to achieve is an essential graphics template where the user can paste their text into this source text property and within Premiere the URL’s in the text will show as a different color than the rest of the text. The tricky part I don’t know how to approach is telling the selector how to recognize URL’s. What I do know about the URL’s is they will most likely all start with https:// and end at a line break or perhaps a special character I can dictate the end user apply.

    Andrei Popa replied 4 years, 3 months ago 4 Members · 6 Replies
  • 6 Replies
  • Filip Vandueren

    January 31, 2022 at 12:22 pm

    A url cannot contain any spaces, so in essence it is a “word”, with some whitespace characters before and after it.

    Set your Expression selector to be based on words, and use this code:

    words = text.sourceText.split(/\s+/);
    word = words[textIndex-1];
    word.startsWith("https://") ? 100 : 0;
  • Andrew Brinkmann

    February 5, 2022 at 3:41 am

    Thank you! This looks like it would be a very effective solution, except After Effects 2022 is telling me word.startsWith is not a function?

  • Filip Vandueren

    February 5, 2022 at 7:17 am

    Hi Andrew, in your project settings, make sure the expressions engine is set to “JavaScript” instead of legacy

  • Andrew Brinkmann

    February 7, 2022 at 1:25 pm

    It worked perfectly. Thank you so much! This is very useful for the templates I’m working on.

  • Arav Roy

    February 9, 2022 at 12:35 am

    Nice.. but I want hightlight many word..

    Can you please help me?

  • Andrei Popa

    February 9, 2022 at 10:06 am

    Hi Arav.

    You really need to be more explicit with that. What words? What is their criteria? How can you identify which one (maybe by index)?

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