Frage

I have received a text written in Microsoft Word which I am trying to continue using in a novel-writing program called Scrivener. This program seems to support RegEx replacing, and I'm trying to make a RegEx do some cleaning up.

Word has made newlines after each line in the text, as such:

Lorem ipsum dolor sit amet, (newline)

etiam liber sonet pro te, (newline)

labores maiestatis te ius, (newline)

(newline)

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

(newline)

Pro id harum admodum hendrerit, praesent maiestatis at sit. (newline)

At sit munere latine virtute, ei vim brute populo, oblique nominavi no (newline)

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

So it seems that where there was actually supposed to be a newline, there are two. So I need a Regular Expression that can match single newlines in a text where the correct newlines typically occur with two newlines.

I am not sure at all how to do this. Could someone show me the way?

Regards, John

War es hilfreich?

Lösung

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. 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top