Help Removing All Punctuation From a Character String

Hi folks,

I am trying to create a simple script that removes all punctuation from a character string that will vary in length and replace the punctuation with a space.

For example, I would like to copy text (e.g. 'To_what_extent_are_you_involved_with_any_of_the_following_professional_organisations), run the macro and return (to the system clipboard) 'To what extent are you involved with any of the following professional organisations' ready for pasting. I want the macro to remove all forms of punctuation, not just underscores.

I have created the following macro (see below) but when I run it simply returns [:punct:], not the character string.
Removing punctuation from character string.kmmacros (3.0 KB)

Any help or advice would be much appreciated!

Try this approach:

Removing punctuation from character string.kmmacros (3.3 KB)

Keyboard Maestro Export

Result:

 To what extent are you involved with any of the following professional organisations   run the macro and return  to the system clipboard   To what extent are you involved with any of the following professional organisations  ready for pasting  I want the macro to remove all forms of punctuation  not just underscores 
4 Likes

Thank you @mrpasini! That seems to work (see below), however, I can't paste the result for some reason.


Any ideas why this would be? When I check the clipboard history switcher, this is all I see....
image
It doesn't seem like the string is making it to the system clipboard...

Thank you again for your help!

Looks like you have a typing mistake in the name of the Variable:

image

4 Likes

@Zabobon's pointed out the error in the variable name. But also worth mentioning that you don't need the variable at all (unless you want to keep your copied text unchanged for later in the macro):

...will do the search and replace on the System Clipboard, ready for you to paste the new text somewhere.

3 Likes

Thank you @Zabobon and @Nige_S - that worked! Thank you very much. This will save me a lot of time :smiley: