ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Replace Text Expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
cow
matthew tully
Replace Text Expression
on Jul 23, 2008 at 3:16:42 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!


Return to posts index

cow
Lloyd Alvarez
Re: Replace Text Expression
on Jul 23, 2008 at 3:32:30 pm

try this:

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


-Lloyd



http://aescripts.com


Return to posts index

cow
Lloyd Alvarez
Re: Replace Text Expression
on Jul 23, 2008 at 3:34:30 pm

in case you are wondering what the gi stands for:

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

http://aescripts.com


Return to posts index


cow
Dan Ebberts
Re: Replace Text Expression
on Jul 23, 2008 at 3:34:36 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



Return to posts index

cow
matthew tully
Re: Replace Text Expression
on Jul 23, 2008 at 4:48:10 pm

Thanks for the tips. Victory!

You guys are awesome!

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


Return to posts index

cow
Dan Ebberts
Re: Replace Text Expression
on Jul 23, 2008 at 5:11:45 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



Return to posts index


cow
matthew tully
Re: Replace Text Expression
on Jul 23, 2008 at 8:47:33 pm

Thanks again Dan!


Return to posts index

Geoff Schultz
Re: Replace Text Expression
on Apr 5, 2017 at 7:27:59 pm

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

replace("“", '"')
replace("”", '"')

But it is only looking at the second string.


Return to posts index

Dan Ebberts
Re: Replace Text Expression
on Apr 5, 2017 at 9:14:19 pm

Try it this way:

replace(/“|”/g, '"')


Dan



Return to posts index

Geoff Schultz
Re: Replace Text Expression
on Apr 6, 2017 at 7:22:13 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?


Return to posts index

Dan Ebberts
Re: Replace Text Expression
on Apr 6, 2017 at 7:35:49 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



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]