Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Remove words from string

  • Remove words from string

    Posted by Jeremy Wick on March 7, 2022 at 8:42 pm

    Trying to come up with an expression that will remove whole words from a string. Removing characters is easy using substr, but not sure if there is a better method for removing whole words.

    
    
    str = "This is just an example.";

    remove = 2;

    output = "This is just"

    Filip Vandueren replied 4 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Filip Vandueren

    March 8, 2022 at 7:00 am

    Hi Jeremy.

    Here’s a quick try, but it replaces all whitespace characters with 1 space i the endresult. Also linebreaks will be gone, so it might be a too simple approach for you:

    str = "This is just an example.";
    remove = 2;
    arr = str.split(/\s+/gi); // yields an array of words
    output = arr.slice(0,-remove).join(" ");

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