Page 1 of 1

Removing redundant spaces

Posted: Sat Jun 06, 2020 9:51 pm
by terrypin
I'm struggling to specify regex that will remove all strings of two or more spaces please?

For example, I want this:

Code: Select all

The quick    brown   fox jumped...        over the lazy      dog.
And another  line   here.
to become this:

Code: Select all

The quick brown fox jumped...over the lazy dog.
And another line here.
Terry

Posted: Sat Jun 06, 2020 10:10 pm
by terrypin
OK, it came to me a few minutes later thanks. I hope this is correct?

Find
([^ ])([ ]+)

and replace with

\1

(That's \1 plus a space.)

Posted: Sat Jun 06, 2020 10:48 pm
by ben_josephs
Your regex matches the non-space character preceding the spaces, and replacing it with itself. Is there a particular reason you are doing this?

This is simpler:
Find what: _+
Replace with: _

[Replace the underscores with spaces]

Posted: Sun Jun 07, 2020 2:06 pm
by terrypin
Thanks, that is indeed much simpler!