> On May 30, 2023, at 10:47 PM, ProjectGuru <[email protected]> wrote:
> 
> I'm looking for a GREP pattern that can delete the newlines that exist ONLY 
> after some text and NOT newline characters that exist between paragraphs For 
> example:
> 
> =================================================
> 
> ORIGINAL TEXT:
> 
> [Ms. Rowling] This is Ms.
> Rowling, author
> of the Harry Potter
> collection.
> And now onto the show.
> 
> [intro music]
> 
> [John] Hi everyone.
> Welcome back to the
> Harry Potter podcast.
> I'm your co-host John Doe.
> 
> DESIRED RESULT:
> 
> [Ms. Rowling] This is Ms. Rowling, author of the Harry Potter collection. And 
> now onto the show.
> 
> [intro music]
> 
> [John] Hi everyone. Welcome back to the Harry Potter podcast. I'm your 
> co-host John Doe.
> 
> =================================================

This search pattern will do the trick.

(?s)(?<=\S)\n(?=\S)

Command-F; put it in the Find: box, put a single space in the Replace: box, 
check Grep, and click Replace All.

Explanation:

(?s) — the string being searched is the entire document, not individual lines.
(?<=\S)) — match the search string only when it is preceded by a 
non-white-space character
\n — the actual search string: a single newline
(?=\S) — match the search string only when it is followed by a non-white-space 
character

When I apply this to your original text, I get:

[Ms. Rowling] This is Ms. Rowling, author of the Harry Potter collection. And 
now onto the show.

[intro music]

[John] Hi everyone. Welcome back to the Harry Potter podcast. I'm your co-host 
John Doe.

Cheers,
Neil Faiman

-- 
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/CDC9FA63-305F-4F0B-B4B8-CD1E2ED321CD%40faiman.org.

Reply via email to