When I need to sort something like this I don’t use GREP since I’m not familiar 
enough with it to get it right with little effort, but you can use the basic 
Find and Replace

Find

\r \r (there’s a space between them because you said there was a space between 
the paragraphs. If you just meant there was an empty line, use \r\r)

Replace with

xxxxxxx

This preserves the gap between paragraphs as xxxxxxx, and now you have a whole 
bunch of lines ending in a return

Then find

\r

replace with

“ “ (a single space)

Then Find

xxxxxxx

Replace with

\r\r

Will separate out all the paragraphs again with a blank line between them. Then 
in case you’ve ended up with 2 spaces anywhere

Find “two spaces” (means 2 spaces, not the words in quotes)

Replace with “one space” (same as above - a single space, not the two words)

Roger



> On Nov 2, 2021, at 11:04 PM, Gavin Brooks <[email protected]> wrote:
> 
> I have a lot of text that has been copied from a PDF, that I need to make 
> into text files for research purposes. When the text copied over, there was a 
> hard line return at the end of every sentences, and a blank space between 
> paragraphs. I need to the lines within the paragraph joined but the 
> paragraphs to remain separate and am looking for a regex to do that:
> 
> For example, the text looks like this:
> 
> This is the 1st paragraph. 
> With a few lines that
> need connected.
> 
> This is another paragraph with
> a blank line between
> it and the previous paragraph.
> 
> I want it to look like this:
> 
> This is the 1st paragraph. With a few lines that need connected.
> 
> This is another paragraph with a blank line between it and the previous 
> paragraph.
> 
> The best that I have been able to come up with is this:
> ([^\r\n])\R(?=[^\r\n])
> 
> But that will also remove the last character of each line, so I get this:
> 
> This is the 1st paragraph With a few lines tha need connected.
> 
> This is another paragraph wit a blank line betwee it and the previous 
> paragraph.
> 
> Any suggestions about how to rewrite the above so that it does not remove the 
> final character?
> 
> Gavin
> 
> 
> 
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a feature 
> request or need technical support, please email "[email protected]" 
> rather than posting here. Follow @bbedit on Twitter: 
> <https://twitter.com/bbedit <https://twitter.com/bbedit>>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/7d23bc98-d5b6-4739-94e8-c08f1efabb28n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/bbedit/7d23bc98-d5b6-4739-94e8-c08f1efabb28n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/BDD0459D-A87C-4131-A92A-4EB255C1977C%40gmail.com.

Reply via email to