How do I combine elements in an array matching a pattern?

Viewed 74

I have an array of strings

["123", "a", "cc", "dddd", "mi hello", "33"]

I want to join by a space consecutive elements that begin with a letter, have at least two characters, and do not contain a space. Applying that logic to the above would yield

["123", "a", "cc dddd", "mi hello", "33"]

Similarly if my array were

["mmm", "3ss", "foo", "bar", "foo", "55"]

I would want the result to be

["mm", "3ss", "foo bar foo", "55"]

How do I do this operation?

2 Answers
Related