Replace Unwanted Line Break With A Word Space

48 views
Skip to first unread message

Andy Nickless

unread,
Apr 25, 2023, 6:15:26 AM4/25/23
to BBEdit Talk
I want to find situations in a text document where there is no Full Stop at the end of the line, but there is (of course) a Line Break (suggesting the Line Break shouldn't be there).
I can find what I want with this:
([a-z])[^\.]\n([a-z])

Unfortunately, I can't work out how to then replace that with a simple Word Space.
When I use \1 \2 it puts in a Word Space, but deletes the last letter off the \1 word and the first letter off \2
Any help will be gratefully received!
Andy

Kerri Hicks

unread,
Apr 25, 2023, 7:25:29 AM4/25/23
to bbe...@googlegroups.com
Barring additional unstated details, this pattern should work:

([a-z])([^\.])\n([a-z])

replacing with 

\1\2 \3

Your current pattern is capturing the second-to-last character of the line with ([a-z]), and then the last character in the line with [^\.] -- but since you didn't put that into a capture group, it will be discarded.

You might consider using

([a-zA-Z0-9\s])([^\.])\n([a-zA-Z0-9\s])

or even just

([^\.])\n

replaced with 

\1 

(space at the end of that replace pattern). 

I plumped up the search string to include capital letters and digits, you may or may not want to do that. And I'm not sure if/why you really need the first capture group at all -- is it important that the second-to-last character and the next-line first character be a letter (or number or space)? 

But at the very least, putting a capture group around that character class that excludes the period should give you what you need.

--Kerri

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" 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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/39810fd8-e55d-40aa-aaf4-a5a12241a6a0n%40googlegroups.com.

Andy Nickless

unread,
Apr 26, 2023, 9:16:46 AM4/26/23
to BBEdit Talk
Thank you for your reply, Kerry.
Very helpful - I modified ([^\.])\n and it's working very well! 
Reply all
Reply to author
Forward
0 new messages