How to transform text immediately after it's copied?

How would I go about transforming text immediately after it's copied? (I would trigger this - starting with the copying action - with a hotkey.)

Specifically, I'd like any instances of ", " in the copied text to be replaced with line breaks. The resulting transformed text would then replace the original text on my clipboard.

I'd be grateful for any guidance! I'm very new to KM, so still figuring things out.

Like this:


1 Like

I would NOT use the Regex \s metacharacter since its definition is too broad:

\s stands for “whitespace character”. Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a carriage return, a line feed, or a form feed.

Unless you need to make additional whitespace characters, like a TAB, I'd just use a plain space in the Search For field:
where 𝍖 is a plain SPACE.

1 Like

Thank you, @mrpasini and @JMichaelTX! It looks like I've got this successfully set up.

In a screenshot, which is what I provided, the whitespace metacharacter is, unlike the space character, visible. Which makes it not only clear here but weeks or months from now when, looking at the action, it will be clear what it does (when you otherwise would not be able to see the space character).

And there is no danger of it being "too broad" in this context.

Precision never hurts, of course. It just isn't always easy to see when it comes to whitespace.

1 Like

I have to disagree here, since \s includes the newline character \n.

Regex is very powerful, but one should always be clear about what they are trying to match, and then design the most accurate pattern to meet that requirement.
In this case, the OP specifically stated a match for comma space:

So that's what we should provide.

Accuracy must always come before readability, even though code readability is high on my list of requirements. As you know, Regex can be very hard to read IAC, if you were not the author.

One final note. If the requirement is not clear what the whitespace is that will occur, I will usually use \h which means SPACE or TAB, and has the bonus of being visible. :wink: