Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Script Expression, how to add character – \

  • Script Expression, how to add character – \

     Walter Soyka updated 2 weeks ago 3 Members · 4 Posts
  • Timur Solomon

    May 13, 2022 at 7:10 am

    Hi all.

    I am writing a script to add a regular expression to a text layer, but when the script is running, the character – \ disappears into the expression.

    textProp.expression = ‘text.sourceText.replace(/\D+/g, “”)’;

    In AE I get – text.sourceText.replace(/D+/g, “”)

    How to fix it?

  • Timur Solomon

    May 13, 2022 at 7:20 am

    The issue is resolved, I just added another character – \

    textProp.expression = ‘text.sourceText.replace(/\\D+/g, “”)’;

    😄

  • Graham Quince

    May 13, 2022 at 7:58 am

    Nice one, thanks for posting the solution, it’ll help the next person struggling.

  • Walter Soyka

    May 14, 2022 at 1:04 am

    Glad you found the solution. As for why that’s the solution, it’s because the backslash is an “escape character” in Javascript strings. It’s not taken literally; rather, it escapes the string and indicates the next character should be not be processed literally. You can use it to add special characters to strings.

    For example, if you wanted to add a single quote to a string enclosed in your script in single quotes, you’d do it with \’. You can also add a tab with \t, a newline with \n, and, as you’ve noted, a backslash with \\.

Viewing 1 - 4 of 4 posts

Log in to reply.

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