Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Parse and remove any numbers from a text layer (Source Text)

  • Parse and remove any numbers from a text layer (Source Text)

    Posted by Ter Ber on November 16, 2017 at 1:13 pm

    Hi,

    I have a text layer that gets the .sourceText from another layer’s markers. The problem is that these markers contain numbers that I want to remove from the string.

    So the expression I now use on the Source Text is orignially Dan Ebberts.

    This gives me a source text string like “11 hello world” and I want it to display just “hello world”.

    Anybody know how to modify Dan’s excellent script to accomplish this?

    m = thisComp.layer("Ketil");
    n=0;
    if (m.marker.numKeys > 0){
    n = m.marker.nearestKey(time).index;
    if (m.marker.key(n).time > time) n--;
    }
    if (n > 0) m.marker.key(n).comment else ""

    Ter Ber replied 8 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    November 16, 2017 at 4:00 pm

    This might work if the numbers are always there and always at the beginning of the comment. Otherwise, it gets more complicated.


    m = thisComp.layer("Ketil").marker;
    n=0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }
    if (n > 0){
    s = m.key(n).comment;
    if (s.indexOf(" ") > -1)
    s.substr(s.indexOf(" ") + 1)
    else
    s;
    }else ""

    Dan

  • Ter Ber

    November 20, 2017 at 10:37 am

    Thanks Dan!

    Your approach makes sense, but I actually found a different answer that worked before you replied. I tried to update my post as “answered”, but was censored by the moderator?!????
    Hopes this reply goes through.

    PS pretty proud of myself figuring out this by myself before Dan himself came to the rescue. My solution worked, but Dan’s solution is probably more well-considered?

    Thanks anyway ????

    m = thisComp.layer("Ketil");
    n=0;
    if (m.marker.numKeys > 0){
    n = m.marker.nearestKey(time).index;
    if (m.marker.key(n).time > time) n--;
    }
    if (n > 0) m.marker.key(n).comment.replace(/[0-9]/g,'') else "not available"

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