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

Automatically changing the color of the first letter of every word within a list of text

New Here ,
Jul 31, 2023 Jul 31, 2023

Hi, I have very basic AE skills and can't figure this one out. I only want every "C" to be yellow and don't want to manually change it every time I change the words. 

Tried an expression that looks for every space " " and then changes the color of the character right next to that, which would be the C's:

 

var userText = text.sourceText;
if (userText.length > 0) {
var modifiedText = userText.replace(/ (\w)/g, " <span style='color:#FCD527'>$1</span>");
modifiedText;
} else {
""
}

 

I'm getting "Error, couldn't turn result into numeric value"

 

Nicolas22126466f746_0-1690827879800.png

 

Thank you for any ideas you may have. 

 

TOPICS
Error or problem , Expressions , How to
755
Translate
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 31, 2023 Jul 31, 2023

If you add an Expression Selector and add this expression to the Amount property, it should get you close to what you're after:

 

userText = text.sourceText.value;
userText[textIndex-1] == "C" ? 100 : 0

 

Translate
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 31, 2023 Jul 31, 2023

I am not sure I understand how this could work. If you add a Fill color, you can only fill the characters based on the start, end, or offset. 

 

If you use an expression on the source text to change the color, you can only do that once, not for every instance of a character like "c."

 

It would be useful to be able to designate a character and fill every instance of that character with a different color, but I don't see any way to do that with the current text engine in After Effects.

 

 

Translate
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 31, 2023 Jul 31, 2023

Is this not what he's asking for?

Translate
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 31, 2023 Jul 31, 2023

The Expression Selector is a feature that I have never used before. Thanks Dan,  I learned something new from you again.

Translate
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 ,
Apr 21, 2025 Apr 21, 2025

A better answer for this question is to use an expression selector to look for a line break in the previous index, that way there are no conflicts if any of the words contain a 'c'. Its pretty simple to check for a space to apply the animator to the first letter of every word:

if (textIndex == 1) {100;} // Set the first character
else {
	PREV = text.sourceText.value[textIndex-2];
	PREV == ' ' ? 100 : 0;
}

 But it gets more complicated when you have line breaks because the expression selector doesn't count them as characters, but the source text does... or maybe it's the other way around? I don't know, it's hurting my brain trying to verbalize it. What I do know is that you have to shift the index by 1 for every line break before the current index, sort of like this:

if (textIndex == 1) {100;} else { // Set the first character
	src=text.sourceText.value;
	upToIndex = SRC.substring(0, textIndex-1); 
	lineBreaks = upToIndex.split(/\r|\n/).length-1;
	PREV = SRC[(textIndex-1)+lineBreaks];
	PREV == '\r' ? 100 : 0;
}

 BUT this won't always work because the 'upToIndex' is checking the wrong spot and may already be on the next line. I don't have time to figure it out at the moment, but it's almost there (I think).

Translate
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
Valorous Hero ,
Apr 29, 2025 Apr 29, 2025
LATEST

Take a look at the Expression that selects a single alphanumeric - it supports multiple-line input strings, has a case-sensitive checkbox, multiple searches, and an instancing delimeter.

https://www.broadcastgems.com/post/the-text-selector-expression-is-arguably-the-most-elusive-adobe-a...


Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Translate
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