Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some badly formatted text which I am attempting to reformat using the OpenOffice.org Writer's Find/Replace functionality which supports regular expressions as defined here.

The problem is some paragraphs have been split into two paragraphs mid-sentence. For example (using ^ to represent the start and $ to represent end of paragraph):

^This is a good paragraph.$

^He said: "This is a good paragraph."$

^But these$

^are two broken ones that should be merged into one.$

I was hoping to construct a regex to find any paragraphs that don't end in a . or " and merge it with the next paragraph (by replacing the end of paragraph with a space, then later I will check for any double spaces).

Doing a find for the search term $ finds (and selects) the end of every paragraph, so it can be replaced. However [^\.]$ finds every paragraph that doesn't end in . but selects the last character not the end of paragraph so I can't replace it.

Any ideas?

share|improve this question

migrated from stackoverflow.com Aug 24 '11 at 1:34

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

Here's what you want. A negative lookbehind:

(?<!\.|")$\n

However, I don't know if OOo Writers supports negative lookbehinds, so instead you can replace with a captured group.

Find:     ([^."])$\n
Replace:  $1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.