How to replace strings of spaces with just one space

1.4k Views Asked by At

I am in TextWrangler, trying to grep for all sets of more than one consecutive space. I want to replace all these instances of multiple spaces with a single space. E.g.,

Find "Cognitive Impenetrability of          Visual Perception" Replace with "Cognitive Impenetrability of Visual Perception"

I've checked all the recommended threads on this and none of them are working for me.

Any advice on how to search (or Grep) for multiple spaces is welcome.

2

There are 2 best solutions below

1
On

In TextWrangler

From menu Search go select Find... to get to the Find & Replace box.

In Find you type: "*" (i.e. two spaces followed by *)

In Replace you type "" (one space)

Don't forget to select box grep, and then press Replace all.

0
On

Here is what worked:

I would look for an instance of multiple spaces, copy two consecutive space-looking characters, and then paste the characters into the "Find" textbox, and add a star:

[mystery character][mystery character]*

Then I clicked the "Replace All" button. This fixed about one-third of the spacing issues.

I continued this method (two more times, I think) until the rest of the space issues (that I found) were fixed.