Is it possible to join array elements with a regex? If so, how do I achieve these requirements?
- Every element should be joined with a spacing character unless it is an empty element.
- Empty array elements should be joined with a new line character (
\n).
That means that this:
["Hello, this is a sentence.", "This is another sentence.", "", "", "Then, there are 2 new lines.","","Then just one new line."]
Should be converted with .join to this:
Hello, this is a sentence. This is another sentence.
Then, there are 2 new lines.
Then just one new line.