Remove spaces in clipboard

Hello!

Named clipboard is: " 5432 7645 9138 8036 " - How to remove all spaces from it?

%Space% can of course be replaced with a standard space character; I've mainly used it here to make it clear what to search for. Please note that the Replace field in both actions has been left blank (which means the spaces will be replaced with nothing, therefore removing them) and that in addition to named clipboards, these actions can also be used to search and replace the system clipboard, variables, files, and more.

2 Likes

Are you just showing both Actions to illustrate two different methods that could be used? Some readers might think you need both actions.

Also, it should be noted that the RegEx \h requires macOS 10.11 or later.

I believe we concluded that [^\S\r\n\f] is the safest horizontal whitespace match pattern.

2 Likes

Good point; apologies if anyone reading this was confused. As you said, my intent was just to show two different methods, and putting them in the same macro for screenshot purposes was just the quickest way to accomplish that. When replacing actual text, you definitely do not need both actions; either one will suffice.

True, but as you yourself say in that thread:

and I'm inclined to agree, not only for accuracy reasons but also because \h is so much easier to remember and type (not to mention much less intimidating to someone who isn't familiar with regex). Given those reasons, and the fact that macOS 10.11 is two years old at this point, I personally feel like \h is safe to recommend as a general-purpose whitespace-targeting regex as a start, and to fall back on [^\S\r\n\f] if it turns out the user is on 10.10 or older.

And hey, if nothing else, at least I'm no longer going around pushing \s like all the other regex amateurs anymore, right? :wink:

2 Likes

I believe there is no difference in accuracy. IOW, these are equivalent:
\h
[^\S\r\n\f]

While I tend to agree with you about using El Capitan as a bottom reference point, I'd suggest that anytime you use an Action or script that requires macOS 10.11+, that you so state. IAC, that is what I try to do.

  • KM8 requires macOS 10.10+
  • I have observed a number of users using macOS prior to 10.11.

When a macro/script may work with Yosemite, I usually CMA by stating something like:

Requires macOS 10.11+ (may work with Yosemite, but no guarantees)

One way to accomplish showing alternate solutions with minimal work is something like this, and put the preferred solution first:

Just some ideas to consider. I really appreciate all the effort you make to help others.

3 Likes

This is what I meant too; I just (clearly) didn't phrase it well :sweat_smile: Apologies for the further confusion!

Another very good point. I really should make some disclaimer snippets for the next time I demonstrate an action or script that requires a recent version of macOS or KM.

Great idea! I will definitely do something like that the next time I demonstrate multiple approaches in a single macro like this.

Consider them duly considered :bow:
Thank you too for the kind words, and for your on-point suggestions! I've learned a lot from your numerous in-depth examples, and also very much appreciate your filling in the gaps when my efforts fall short :slightly_smiling_face:

2 Likes