是否可以使用正则表达式连接数组元素?如果是这样,我如何达到这些要求?
- 每个元素都应该用一个空格字符连接,除非它是一个空元素。
- 空数组元素应与换行符 (
\n
) 连接。
这意味着:
["Hello, this is a sentence.", "This is another sentence.", "", "", "Then, there are 2 new lines.","","Then just one new line."]
应该转换.join
为:
Hello, this is a sentence. This is another sentence.
Then, there are 2 new lines.
Then just one new line.