How to dash separate selected text?

I wish to lowercase and dash separate selected text. So if I select something like :

Hello World, it would give me hello-world.

I get how to do the first three actions :

But I am not sure how to do the dash separation action. I don't believe KM provides a native way to do it.

One way I see how I can do this is by using regex and swapping all spaces with a dash, whilst trimming whitespace beforehand but perhaps there is a better way to do this as I am not too fond of regex.

Well the regex was actually super easy as it turns out :smiley:

It isn’t super robust though but I will update it once I see it failing me on certain inputs.

While regex is probably the better way to handle this scenario, it isn't necessary. You can search and replace regular space characters just as well as any other character (as you've discovered in your own regex). I have a couple of old simple macros that do just that:

If you do want to use regex though, I would suggest just searching for \s+, as that will replace any number of white-space characters in your text (with your current search pattern, a mistyped double space will result in hello- world).
And as a newcomer to regex myself, I would encourage you to push yourself to learn and use it more. My own understanding is still rudimentary, yet even so it's still proven immensely useful.

1 Like

Can I ask why you delete Past Clipboard 2 times here :

Or it was some typo?

Nope, not a typo. I often delete the most recent two clipboard items like this in my text processing macros so they don’t clutter up my clipboard history. The idea is to get as close as possible to performing the text processing in-place, as if there were no need to transfer the text to the clipboard or a variable first.

14 posts were split to a new topic: RegEx for Horizontal Whitespace (\s \h \t blank etc)

As you guys can probably see, I have moved all posts discussing “horizontal whitespace” to a new topic, so it is more easily referenced and found.


RegEx for Horizontal Whitespace (\s \h \t blank etc)