我有一个名为“Section 1”...“Section 20”的几个部分的字符串,并且希望将这个字符串拆分为这些单独的部分。这里有一个例子:将字符串拆分为基于标题的部分
Stuff we don't care about
Section 1
Text within this section, may contain the word section.
And go on for quite a bit.
Section 15
Another section
我想这个分成
["Section 1\n Text within this section, may contain the word section.\n\nAnd go in for quite a bit.",
"Section 15 Another section"]
我感觉不得到它的权利相当愚蠢的。我的尝试总是捕捉一切。现在我有
/(Section.+\d+$[\s\S]+)/
但我无法从中得到贪婪。
一旦遇到“第1部分”,是否要捕获其他所有内容?或者,你想忽略第20节之后的文字吗?您想要在部分,*总是*紧随其后的行,还是在段之间会有段落/空白行? –
这个例子很清楚。他希望每个部分(标题+文本)都是数组。 – robertodecurnex
有帮助吗? –