0

我收到了一篇用 Microsoft Word 编写的文本,我正在尝试在一个名为 Scrivener 的小说写作程序中继续使用它。该程序似乎支持 RegEx 替换,我正在尝试让 RegEx 进行一些清理。

Word 在文本中的每一行之后都添加了换行符,如下所示:

Lorem ipsum dolor sit amet,(换行符)

etiam liber sonet pro te,(换行符)

Labores maiestatis te ius,(换行)

(新队)

“cu有exerci mentitium apeirian。” Ad vel probo eruditi delicatissimi。(新队)

(新队)

Pro id harum admodum hendrerit, praesent maiestatis at sat。(新队)

at sat munere latine virtute, ei vim brute populo, oblique nominavi no (newline)

其他 Quo et vituperata percipitur, sed sint putent adolescens in. (newline)

所以看起来实际上应该有一个换行符的地方,有两个。所以我需要一个正则表达式,它可以匹配文本中的单个换行符,其中正确的换行符通常与两个换行符一起出现。

我完全不确定该怎么做。有人能给我指路吗?

问候,约翰

4

1 回答 1

0

I don't know what is the support of Regexes in Scrivener, but maybe this regex can help :

(?<!\r\n)\r\n(?!\r\n)

Explanation :

(?<!\r\n) # negative look behind for new line
  \r\n    # new line
(?!\r\n)  # negative look ahead for new line

It will match each new line that is not followed by another new line and that does not follows a new line.

Maybe you will need to use \n instead of \r\n.

I tested with Notepad++ with this input :

Lorem ipsum dolor sit amet, 
etiam liber sonet pro te, 
labores maiestatis te ius, 

"cu has exerci mentitum apeirian." Ad vel probo eruditi delicatissimi. 

Pro id harum admodum hendrerit, praesent maiestatis at sit. 
At sit munere latine virtute, ei vim brute populo, oblique nominavi no 
nec. Quo et vituperata percipitur, sed sint putent adolescens in. 

Use the Replace feature with regex options :

Notepad++ Replace with Regex

And obtained this result after replacement :

Lorem ipsum dolor sit amet, etiam liber sonet pro te, labores maiestatis te ius, 

"cu has exerci mentitum apeirian." Ad vel probo eruditi delicatissimi. 

Pro id harum admodum hendrerit, praesent maiestatis at sit. At sit munere latine virtute, ei vim brute populo, oblique nominavi no nec. Quo et vituperata percipitur, sed sint putent adolescens in. 
于 2013-10-17T23:03:12.247 回答