我有这个集合(点数可变,这里是 2):
A
This is some Text belonging to A
This also belongs to A
B
This should be with B
same with this
...
...
我希望它最终成为这样的字符串:
A This is some Text belonging to A This also belongs to A
B This should be with B same with this
我的尝试是这样的:
answer.scan(/^([A-Z].+?(?=^[A-Z]))/m).map { |d| d.delete("\n") }.join("\n")
问题是这与最后一组不匹配(您可以假设字符串以最后一组结尾)有什么想法吗?:)
编辑1:修复了一个复制错误并在Rubular中尝试了一个新的正则表达式,哪种方法有效,但仍有一些不必要的匹配?