这里是一个小文本,看起来像restructuredText。
This is a sentence to catch.
Title that should not be caught
-------------------------------
Another sentence to catch.
我想要一个正则表达式,它捕获不是标题的两行,并保留is标题的句子。
---
行。我已经完成了/^(?!(---))[^\n]+/gm
。它将行留在标题下。它给了我:This is a sentence to catch.
Title that should not be caught
Another sentence to catch.
Title that should not be caught
)上方保留句子?我尝试过/^(?!(---))[^\n]+(?!\n---)/gm
,这给了我:This is a sentence to catch.
Title that should not be caugh
Another sentence to catch.
问题是它没有抓住前面的字母 \n---
呼唤我想抓住的没有<< [整个句子。我想的是:
This is a sentence to catch.
Another sentence to catch.
我该怎么办?编辑:
感谢您的回复效果很好(我不确定是否了解所有内容,但我会考虑一下……)。如果您同意,让我们进一步扩展该问题。新玩具示例:
This is another title not to catch, Ha ! ======================================== This is a sentence to catch. Title that should not be caught ------------------------------- Another sentence to catch.
如您所见,我在===
行中添加了另一种标题。使用Tân的正则表达式,我得到:
======= This is a sentence to catch. Another sentence to catch.
测试1之二:我已经测试过
.+(?![\w\s\n-=]+).+
,但没有发现任何问题:(
.+(?![\w\s\n-]+).+