Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Replace Text Expression

  • Replace Text Expression

    Posted by Matthew Tully on July 23, 2008 at 3:16 pm

    Howdy,

    Problem: I am loading text dynamically from an XML file to write credits for several artists using a script. When I pull the data into AE it keeps introducing a string of escaped code. I can’t seem to solve the broken code, but the string it dumps in is always the same, its a unicode value.

    Solution(i think): attach an expression to search for the escaped code in Source Text. Replace the unicode with another string of text using if/else.

    Questions: Here is loosely what I imagined using. How do I make it search and find just the one string?

    if (text.sourceText = “\xyz”) text.sourceText = “replaced” else (text.sourceText);

    right now this code would return “replaced” regardless of what is in the source text. So its totally broken. I understand why, but I don’t know how to tell it to find just one string in sourceText. Please help!

    Thanks in advance. This forum has helped me so many times!

    Mikhail Doroshenko replied 7 years, 1 month ago 5 Members · 11 Replies
  • 11 Replies
  • Lloyd Alvarez

    July 23, 2008 at 3:32 pm

    try this:

    text.sourceText.replace(/something to replace/gi, “what to replace it with”)

    -Lloyd

    https://aescripts.com

  • Lloyd Alvarez

    July 23, 2008 at 3:34 pm

    in case you are wondering what the gi stands for:

    search (g)lobally for the string and be case (i)nsensitive

    https://aescripts.com

  • Dan Ebberts

    July 23, 2008 at 3:34 pm

    You should be able to fix the problem in the script, but if not, this expressions should do it:

    text.sourceText.replace(/xyz/,”replaced”)

    Dan

  • Matthew Tully

    July 23, 2008 at 4:48 pm

    Thanks for the tips. Victory!

    You guys are awesome!

    Do either of you have any good resources for expressions that control text?

  • Dan Ebberts

    July 23, 2008 at 5:11 pm

    Any good JavaScript reference will have a section on string methods, which will be very helpful. It should also include a section on “Regular Expressions” (not related to AE expressions) which are used by some of the string methods.

    Dan

  • Matthew Tully

    July 23, 2008 at 8:47 pm

    Thanks again Dan!

  • Geoff Schultz

    April 5, 2017 at 7:27 pm

    How would I replace multiple strings of text?
    Currently I have:

    replace(“‚Äú”, ‘”‘)
    replace(“‚Äù”, ‘”‘)

    But it is only looking at the second string.

  • Dan Ebberts

    April 5, 2017 at 9:14 pm

    Try it this way:

    replace(/‚Äú|‚Äù/g, ‘”‘)

    Dan

  • Geoff Schultz

    April 6, 2017 at 7:22 pm

    what if I am wanting to replace multiple codes with different characters, like a quotation mark, apostrophe & an em-dash all on 1 layer of text?

  • Dan Ebberts

    April 6, 2017 at 7:35 pm

    I suppose you could do something like this:

    txt = thisComp.layer(“text”).text.sourceText;
    txt.replace(/”/g,”x”).replace(/’/g,”y”).replace(/-/g,”z”)

    Dan

Page 1 of 2

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