ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Is there a way to control regex?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Yoan Boisjoli
Is there a way to control regex?
on Jul 17, 2020 at 8:08:47 pm

Hi! I'm making mogrt for a client and the client would like to a word in a paragraph be a different color.

I've added an expression selector to a fill animator in my text layer and applied a simple expression that targets a word using regex.

Although, my purpose would be to have a variable in the regex. The variable would be another text layer that the client would control.

But it's not as simple as I thought because now the regex is looking for "txt" (my variable name).

Any way you think it's possible?

var txt = thisComp.layer("select").text.sourceText; //variable pointing to text layer
var RE = /(txt)/gi; //regex which holds the variable
var txt = text.sourceText.replace(RE, function($0) {
return '~'.repeat($0.length);
});

if(txt.charAt(textIndex - 1) == '~'){
100;
} else {
0;
}


Return to posts index

Filip Vandueren
Re: Is there a way to control regex?
on Jul 18, 2020 at 6:28:49 am

Yes,
construct the regexp from a string instead of a literal;

var RE = new RegExp( '(' + txt + ')' , 'gi');



Return to posts index

Yoan Boisjoli
Re: Is there a way to control regex?
on Jul 20, 2020 at 2:15:36 pm

Very cool! Thanks Filip!


Return to posts index

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