• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Expression : replace()

Explorer ,
Jul 29, 2024 Jul 29, 2024

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

 

  • It seems to work only on Source text and not numeric values. Even if it can replace numbers.
  • When not using "g" it only works on the first character found, even if you search for severals characters with "|".
  • $ seems to be an important. It displays "[Helper Object]".

 

 

Thanks to :

Dan Ebberts (on Creative Cow)
Lloyd Alvarez (on Creative Cow)

TOPICS
Expressions

Views

199

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 29, 2024 Jul 29, 2024

That's correct. It's a String method from core JavaScript.

Votes

Translate

Translate
LEGEND ,
Jul 29, 2024 Jul 29, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2024 Jul 29, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 29, 2024 Jul 29, 2024

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 ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2024 Jul 29, 2024

Copy link to clipboard

Copied

LATEST

That's correct. It's a String method from core JavaScript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines