Clean up spaces (duplicate and/or non-breaking)

Somehow, a number of company names were entered in to a tool we use at work with nbsp in the name… and somehow there are duplicate spaces.

I’m hoping to find something which would take this input:

One Two  Three 

and end up with

One Two Three

Where the nbsp between the first & second word would get replaced with a single space.
the two spaces in between Two and Three would get turned in to once space.

and if it’s not too much to add, cleaning up trailing spaces would be nice… but less important for our needs.

PS This seems to be a close relative to this thread

But I couldn’t figure how to do one replacement (nbsp with space) then pass the result in to the space deduplicator)

1 Like

PS … maybe using the Accordion icon works? 🪗 Accordion Emoji | Meaning, Copy And Paste because we’re squeezing spaces together… and because what else would use accordion? lol

2 Likes

A slight modifiaction of the snippet in the other thread does the trick:

// #popclip
// name: Remove multiple spaces redux
// icon: iconify:game-icons:accordion
// after: paste-result
// language: javascript
return popclip.input.text.replace(/\s+/g, " ");

(The above block is an extension snippet — select it then click “Install Extension” in PopClip.)

Here the \s matches any kind of space including nbsp, rather than just the vanilla space.

3 Likes

Brilliant!

AND what a wonderful way to install a snippet. After years and years of use… Popclip never ceases to amaze.

2 Likes

Thanks, I just installed it.

2 Likes