What if simply exclude carriage return?
Thanks, but no. That post refers to the built-in Remove Trailing Whitespace query that I mentioned does not work for my needs.
I'm not sure why the reply didn't get posted here, but I got an email answer that worked:
I shortened that to the following, which also is working for me:
Your reply disappeared for me...
However, here's "improved" version:
it works on my side...
Oooh, it was a hard day....
Simple \h+$ is just enough, blind me!
The \h is nice, I didn't know about that! I had to look it up, so for anyone else that doesn't know:
\h is horizontal whitespace
\v is vertical whitespace (finds both hard and soft returns)
I'd probably use +? instead of + for shortest match. Not sure if it's necessary, but it would be safer, right?
So to break \h+?$ down:
\h = horizontal whitespace
+? = repeat one or more times (shortest match)
$ = at end of paragraph
That works very well and I like the elegance of it, but if there are soft returns, it also removes the space before the soft return.
When using \s*?(?=\r) I found it does not remove the spaces before soft returns, which is a little better for me. So far that looks like the winner for my exact needs.
Thanks everyone for the help! I always enjoy learning something new and hope others can benefit too.
Yeah, I’m with Obi-wan here. You should use 'horizontal space', not 'any white space', anyway.
Negative Lookahead works nicely. And no need for 'shortest match', IMHO.
Your 'working' regex \s*?(?=\r) finds a lot of false positives to me (well, harmless), just use Find Next to see...