Ruby 把段落分成几行

Ruby 把段落分成几行,ruby,Ruby,假设我有这段 Before you can begin to determine what the composition of a particular paragraph will be. you must first decide on an argument and a working thesis statement for your paper. What is the most important idea that you are trying to convey to your

假设我有这段

Before you can begin to determine what the composition of a particular paragraph will be. you must first decide on an argument and a working thesis statement for your paper. What is the most important idea that you are trying to convey to your reader. The information in each paragraph must be related to that idea. In other words. your paragraphs should remind your reader that there is a recurrent relationship between your thesis and the information in each paragraph. A working thesis functions like a seed from which your paper. and your ideas, will grow. The whole process is an organic one—a natural progression from a seed to a full-blown paper where there are direct, familial relationships between all of the ideas in the paper.
我应该给我们写什么代码,以便将这一段分成几行?就像这样

Before you can begin to determine what the composition of a particular paragraph will be.

you must first decide on an argument and a working thesis statement for your paper. 

What is the most important idea that you are trying to convey to your reader. 

The information in each paragraph must be related to that idea. 

In other words. 

your paragraphs should remind your reader that there is a recurrent relationship between 
your thesis and the information in each paragraph.

A working thesis functions like a seed from which your paper. 

and your ideas, will grow.

The whole process is an organic one—a natural progression from a seed to a full-blown paper where there are direct, familial relationships between all of the ideas in the paper.
我曾想过使用gsub,但我认为这是不可能的。有什么建议吗?

我认为这很有效

.split(/(?<=[\.\?\!])\s*/).each { |i| puts i; puts '' }

.split(/(?你的意思是分成不同的句子吗?为什么gsub是不可能的?
sParagraphicalForm.gsub(/([^\s\w''\-])/,“$1\n”)
应该能让你朝着正确的方向前进。如果这太激进,你可以试试,
sParagraphicalForm.gsub(/([\.!\?])/,“$1\n”)
然后如果你想在数组中使用它,只需在返回字符串上调用
.chomp
。那问题呢!?!真的很生气!!!!或者很困惑???(而且不是每个人都使用大写或句点)处理@tadman的评论,他提出了一个很好的观点,你可能想把
([^\s\w'\-]+)
([\.!\?)
作为你的配对组,或者如果你想玩,那将是
(?简单而优雅,但作为一个提示
[\.\.\?\!]
应该是
[\.\?\!]
(\.\.\?\!)
,因为方括号不支持正则表达式中的
。这种语法是为插入式组保留的。您可能也不需要逃避
,但我不能100%肯定这一点。好眼力。
[\.\?\!]
就是我要去的地方。您可以使用
拆分(…)。加入(“\n\n”)
如果你想让它返回一个带双换行符的字符串,我更喜欢这样。