ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change Color of text inside parenthesis

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Raj Sha
Change Color of text inside parenthesis
on Jul 11, 2019 at 5:15:25 pm

Hello Everyone,

This might sound simple to you, but I have 0 knowledge of expressions.

I am trying to find a way to change color of a certain text in text box.

Anything inside parenthesis should be of yellow color and rest of the color should be default white.

For Ex. 1. (adj) Not being in a specified place
2. (v) Go away or leave

So in above example, I need to color (adj) and (n) leaving everything else same.

Please help

Thanks,
Raj


Return to posts index

Andrei Popa
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 7:20:43 am

I'm not that good with regular expressions, but i remembered this post of Oleg Pirogov and after few searches on Stack Overflow i came up with this. Worked on my test. I used two occurences, one with space and one without.

So add a text animator, fill color, rgb. To this animator add selector>expression. In the expression field write this:

var t = text.sourceText;
var regex = /\(([^)]+)(?=\))/g;

function indexMatched(index){
var matched = false;
var match;
var i=[];

while ((match = regex.exec(t)) !== null){
matched |= match.index<index & index<match.index+match[0].length;
i.push([match, match.index, match.index+match[0].length]);
}
return matched;
}

indexMatched(textIndex-1) ? 100 : 0;


Andrei
My Envato portfolio.


Return to posts index

Andrei Popa
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 11:48:11 am

Without the i part...

var t = text.sourceText;
var regex = /\(([^)]+)(?=\))/g;

function indexMatched(index){
var matched = false;
var match;

while ((match = regex.exec(t)) !== null){
matched |= match.index<index & index<match.index+match[0].length;
}
return matched;
}

indexMatched(textIndex-1) ? 100 : 0;


Andrei
My Envato portfolio.


Return to posts index


Raj Sha
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 1:10:33 pm

Thank You for taking time out and replying Andrei.

I tried your code and it gives me this error.




Can you help?


Return to posts index

Andrei Popa
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 1:43:26 pm

I am pretty sure you put the expression where it was not supposed to be.

Here is a short screen rec.
13527_tutorial.mp4.zip

Andrei
My Envato portfolio.


Return to posts index

Raj Sha
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 2:07:08 pm

Thank You Andrei!!

You were correct, I was pasting the expression at some place else.

So this fixes the problem for first occurrence of parenthesis. But for second parenthesis, it moves the red color to the next character and then to next character if there are more parenthesis.

Attaching Screenshot.



Return to posts index


Andrei Popa
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 2:21:34 pm

That is because the amount selector does not count the enters at the end of the line. This works for multiple paratheses, as long as they are only on the first line or in a textbox. I can't think of a solution right now. The best i can come up with is split into multiple layers so you don't need to use enter before any paratheses.

Andrei
My Envato portfolio.


Return to posts index

Raj Sha
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 2:37:05 pm

Thank You Andrei for all your support and help!! ☺

I will wait for someone to reply, if they can come up with any solution or will split my text into multiple layers.

Thank You once again ☺
Rajat


Return to posts index

Andrei Popa
Re: Change Color of text inside parenthesis
on Jul 12, 2019 at 2:43:33 pm

Nvm, i got this. The kind of problem that does not go out of your head...

var t = text.sourceText;
var splitText = t.split("\r");
var regex = /\(([^)]+)(?=\))/g;

function indexMatched(index){
var matched = false;
var match;
while ((match = regex.exec(t)) !== null){
matched |= match.index<index & index<match.index+match[0].length;
}
return matched;
}

function placeInLines(index){
i=0;
maxIndex = 0;
while(index>maxIndex){
maxIndex += splitText[i].length;
i+=1;
}
return i-2;
}

indexMatched(textIndex+placeInLines(textIndex)) ? 100 : 0;


Still, i think there are better solutions. I would like to see someone solve this in a more elegant manner.

Andrei
My Envato portfolio.


Return to posts index


Raj Sha
Re: Change Color of text inside parenthesis
on Jul 13, 2019 at 5:29:21 pm

Yay!!

Exactly what I was looking for.

Thank You So So Much Andrei. God Bless You!!

I am pretty sure many more people will be looking for exactly same thing. You have helped us all.

Thank You once again for all your support and time.

Cheers!! :)


Return to posts index

Raj Sha
Re: Change Color of text inside parenthesis
on Jul 15, 2019 at 3:41:50 pm

Hello Everyone,

I am really sorry, but I forgot to mention that the word inside parentheses should also turn italics?

Is this achievable?

Thanks in Advance!


Return to posts index

Raj Sha
Re: Change Color of text inside parenthesis
on Jul 16, 2019 at 7:43:24 am

Just checking if anyone can help me with this?


Return to posts index


Andrei Popa
Re: Change Color of text inside parenthesis
on Jul 16, 2019 at 10:01:11 am

Hey. Thank you very much for the kind word, it really means a lot.

Now. To make the letters also italic, just click the add(from where you added expression selector), select Property and then Skew. Now modify the Skew value to what you wish.

Andrei
My Envato portfolio.


Return to posts index

Raj Sha
Re: Change Color of text inside parenthesis
on Jul 16, 2019 at 10:26:05 am

Hi Andrei,

This solution is doing the job but the italics font and the skew font looks completely different and also when you skew the text it touches the Right Parentheses.

Any way to make it italics in expression?

Thank You,
Rajat


Return to posts index

Raj Sha
Re: Change Color of text inside parenthesis
on Jul 17, 2019 at 7:23:55 pm

Still looking for a solution. if anyone can help?

Thank You!


Return to posts index

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