Reformat a Telephone Number on the Clipboard

I am very much a novice with no real programming experience...but I wanted to do something similar: Select a phone number, strip out all characters that were not digits, then apply a standarized format of (xxx)xxx-xxxx. This standardized format is mostly just optics for us...we want all phone numbers in a database to be input the same way.

Here's how I did it, I would love to know how to make it cleaner using Peter's search and replace Variable above.

Variables, to me, are uncharted territory. I figured there was a way to do this while doing my own experimentation...but I didn't even know where to begin. It's a learning curve...and a very cool one at that! phoneformat.kmmacros (6.4 KB)

Hey Greg,

Here's how to do it with Search and Replace Clipboard actions (using a regular expression and ignoring case).

(Note — the actions have been renamed to explain what they do).


Reformat a Telephone Number on the Clipboard.kmmacros (4.2 KB)


Thank you…that’s way better than the mess I created!