Copy link to clipboard
Copied
Hi,
I am trying to get as much information as possible about the expression .replace() .
I looked the Ae expression documentation, forums, asked Adobe assitants, but never found official and complete informations about this expression. So If you have a link or informations yourself, feel free to let us all know in the comment, I'll actualise this post.
Note that I'm not a pro and English is not my first language, so if there are errors, tell me what to change.
Here are the informations I have already :
// g : search (g)lobally for the string
// i : search while been case (i)nsensitive
var a1 = [numerical or alphabetical value];
var a2 = [second numerical or alphabetical value];
...
var b = [numerical or alphabetical value inside ""];
text.sourceText.replace(/a1|a2/gi, b)
exemples :
text.sourceText.replace(/e/gi, 3)
// before : HELLO everyone
// after : H3LLO 3v3ryon3
______________
text.sourceText.replace(/e/, 3)
// before : HELLO everyone
// after : HELLO 3veryone
______________
text.sourceText.replace(/E|o/g, 1)
// before : HELLO everyone
// after : H1LLO every1ne
______________
text.sourceText.replace(/e/gi, 3).replace(/o/gi, "@")
// before : HELLO everyone
// after : H3LL@ 3v3ry@n3
Thanks to :
Dan Ebberts (on Creative Cow)
Lloyd Alvarez (on Creative Cow)
That's correct. It's a String method from core JavaScript.
Copy link to clipboard
Copied
The syntax inside the parentheses is simply based on regular expressions. Letters like g, w, b, i etc. define search parameters/ filters, the actual strings are followed by that. Numbers would be filtered with \d as in "digits", stuff like $ defines the start of the search (string anchor) and would not be necessary for single words, but may be relevant for complex search patterns. There's a ton of other stuff. RegEx can be powerful, but is also hard to understand. I suggest you look it up in a generalized web search.
Mylenium
Copy link to clipboard
Copied
Yes, the JavaScript implementation of regular expressions (RegExp) is what you're looking for. There's a nice section in my favorite JavaScript book "JavaScript The Definite Guide" by David Flanagan.
Copy link to clipboard
Copied
Hi, thank you for the answer.
If I understand it right the replace() expression is a common code in JavaScript, therefore Adobe didn't create it for Ae's expression ?
Copy link to clipboard
Copied
That's correct. It's a String method from core JavaScript.