Prune punctuation from clipboard content

My clipboard content will be numbers and punctuation, and I want to paste the numbers only. The numbers that appear in the following formats:
12/345,678
or
23/456-789

I need to copy the numbers then paste without the / or , or -
I came up with a solution that works, and I paste with the hot key trigger command-J rather than usual command-V. In these examples, the results are 12345678 and 23456789 when I use my command-J Macro, which is what I want.

My solution seems inelegant. Is there a more succinct way?

Prune some punctiation.kmmacros (2.9 KB)

Hi, @anothersite. Welcome to the forum!

Here's another way:

Download: Prune some punctiation v2.kmmacros (2.0 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 13.5.2 (22G91)
  • Keyboard Maestro v10.2

In the macro I shared, note the following:

  1. There is one Search and Replace action and the regex pattern is: /|,|- The vertical bar, a.k.a. pipe, is used to indicate or.

  2. The default, All Matches is selected (in the gear menu).

  3. The output, i.e., to, can be directed to the System Clipboard but I prefer to use Source when it's the same as the Search value.


@anothersite, I like to share the following references to new forum users:

2 Likes

Just an FYI for your regex, \d matches any digit, and \D matches any non-digit. So your search regex could also be \D to remove everything that is not a digit.

The available characters are documented in the ICU Documentation (liked to from the Help menu in Keyboard Maestro).

3 Likes

Very helpful. Thanks!

1 Like

That's really succinct. Cool.

Hi, @anothersite. I'd like to point out two other handy tips:

  1. Note the gear menu includes Help at the bottom. That's a quick way to get the wiki page that details the action.

  2. Not directly relevant to your question, but many Keyboard Maestro users choose to use Edit>Insert Action>By Name... (⌃⌘A) to add actions.

2 Likes