Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Best way to split words and include spaces

  • Best way to split words and include spaces

    Posted by Edward Clayton on October 24, 2022 at 4:03 pm

    What would be the best way to .split() text to include spaces, while excluding line breaks from the result?

    I’m guessing there’s a way use .split(/\s/) and then add the spaces later, but I’m stumped.

    Paul Ducco replied 3 years, 6 months ago 3 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    October 24, 2022 at 7:16 pm

    This is one way, don’t know it it’s the best.

    t = 'apple banana \rcow dog\relephant';
    words = t.match(/\S+ */g);
  • Edward Clayton

    October 24, 2022 at 7:18 pm

    Exactly what I was looking for. Thank you!

  • Paul Ducco

    October 24, 2022 at 8:38 pm

    Filip to the rescue!

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