Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Conditional RegEx

  • Posted by Yoan Boisjoli on March 14, 2021 at 7:06 pm

    Not sure if this was covered before (can’t seem to find it online).

    I’m trying to have a mogrt warn the user if the year entered in a text layer is valid or not.

    I have another text layer with the warning written and I want to have its opacity be triggered if the year is not valid.

    I wrote a condition and AE doesn’t give me an error but it doesn’t seem to work.

    var txt = thisComp.layer("YEAR").text.sourceText;

    var newReg = ("/^\d{4}$/g");

    txt == newReg ? 0 : 100;

    The opacity stays at 100%.

    I don’t know if I should be using match() here or not.

    Any clues?

    Thanks!

    Yoan Boisjoli replied 3 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Fabrice Leconte

    March 15, 2021 at 2:26 am

    Match or test should work.

    thisComp.layer("YEAR").text.sourceText.match(/^\d{4}$/g)?0:100

    // OR

    (/^\d{4}$/g).test(thisComp.layer("YEAR").text.sourceText)?0:100

    https://imgur.com/a/34ldDxE

    View post on imgur.com

  • Yoan Boisjoli

    March 15, 2021 at 11:40 am

    Amazing! I wasn’t too sure of how to use match() but you just taught me how! Oh and you also showed me the existence of “test” hehe

    Un gros merci Fabrice! ?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy