Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Replace certain characters in a text field with different characters.

  • Replace certain characters in a text field with different characters.

    Posted by Christopher Rutherford on September 1, 2020 at 4:20 am

    I’m currently building text animation and need to replace certain characters with certain symbols dynamically. Specifically, I’d need to replace all characters excluding spaces with the letter b.

    I realize I can do “.replace” on a per character basis, but would it be resource intensive for AE to comb through 52 “.replace” strings every time it hits a text layer?
    And even if I do, I notice that if there are two characters in a row to be replaced, the second one is left alone for some reason.

    Any thoughts?

    Filip Vandueren replied 6 years ago 2 Members · 1 Reply
  • 1 Reply
  • Filip Vandueren

    September 2, 2020 at 7:00 am

    You’d have to do a replace with regular expressions in stead of strings.
    read all about them here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

    for example:

    t=text.sourceText.value;
    t.replace(/\w/g, "b");

    would replace all \w = “word” characters by the string “b”
    (but it would keep whitespaces, punctuation, symbols some accented letters,…)

    or

    t=text.sourceText.value;
    t.replace(/[^ \r\n\u0003]/g, "b");

    would replace anything that’s NOT (because of the [^…] syntax) a space, a carriage return, a newline, an end-of-text meta character (unicode 0003 = shift-enter) by the string “b”

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