Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions .replace method not working

  • .replace method not working

    Posted by Pete Menich on May 15, 2022 at 7:28 am

    I cannot get the expression to ‘find a character in a string of text and replace it’ to work.

    I’ve been combing the web and trying all the examples & I either get a syntax error (invalid or unexpected token) or it doesn’t do anything.

    For example: I have a text layer with every character in the alphabet like this…

    abcdefghijklmnopqrstuvwxyz

    I then apply this expression to the source text…

    text.sourceText.replace(/\d/gi, “test”)

    then nada. zip. nuthin.

    any ideas?

    Pete Menich replied 1 year ago 2 Members · 4 Replies
  • 4 Replies
  • Filip Vandueren

    May 15, 2022 at 9:38 am

    Hi Pete,

    The regex you created will replace every digit (character class \d) with “test”, and there are no digits in your sourceText.

    if you wanted to replace the letter d, don’t use a backslash, if you wanted all non-digit characters, use \D

  • Pete Menich

    May 15, 2022 at 11:09 am

    still doesn’t work.

    I tried several permutations & still nothing

  • Filip Vandueren

    May 15, 2022 at 11:16 am

    Strange. This works for me…

    text.sourceText.replace(/d/gi, "test");

    result is abctestefghijklmnopqrstuvwxyz

    both in legacy extendscript and javascript modes.

    (edit: typos, and watch out for curly quotes that the websites loves to add, but invalidates javascript code)

  • Pete Menich

    May 15, 2022 at 11:46 am

    weird. Now it works. Amazing!

    Thanks Filip

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