Clipboard search replace: how to add TAB?


I want to

  • replace "* " (star followed by space followed by TAB at the beginning of a line)
  • with ### (### followed by space)

In the snapshot below, all is fine except that I don't know how to add the TAB after star -space

thanks in advance for your time and help

Tab = \t
Return = \r
New Line = \n

I think we need to use regex search.

@noisneil @martin
I tried and it does not work. Have to use a regex I think. thank you both

Works here. :man_shrugging:t2:

Replace "* \t" with "###".kmmacros (20 KB)

Macro screenshot

1 Like

I made a mistake and now understand. profuse apologies.
The objective was to convert a markdown list to a structured text with headers.
thanks again and very sorry

1 Like

No need to apologise. Happy I could help. :+1:t3:

1 Like

Wow...indeed \t in RegEx String Search may be taken as a Tab or a literal string \t. I didn't know that!

@peternlewis, is it what is intended?

RegEx.kmmacros (3.8 KB)

Screenshot_2022-04-30 14.07.58_xEne6j

1 Like

Always start with the objective.

Without that context, these exercises fall straight (even with the best will in the world) into:

1 Like

thank you for your comment. Yes you are 100% right, and thanks for the wiki snapshot.

1 Like

Sorry, but I'm a bit confused by this.

Action 1 sets a string with 'asterisk-space-tab' in it with the tab typed on the keyboard, action 2 replaces 'asterisk-space-tab' with 'hash-hash-hash'.

Action 3 sets a string with 'asterisk-space-tab' in it with the tab entered as '\t', action 4 replaces 'asterisk-space-tab' with 'hash-hash-hash'.

Do you perhaps mean that "when defining a string variable you can enter a tab directly with the tab key or with \t"? Or am I, as usual, missing the point entirely!?

1 Like

Yes, of course \t can mean either \t or [TAB], depending on whether the \t is processed, as generally controlled by the gear menu.

These two:


Are exactly equivalent, assuming the setting on the action is configured to process text tokens normally:


In both cases, the variable will have a TAB character in it.

And in both cases, the Search & Replace will process the \t as a tab as well, and so in both cases the replace will happen.

Note that if the Search & Replace is configured to be a regular expression instead of a plain text search, then Keyboard Maestro will not replace the \t with a TAB character however, instead the regular extension system will consider \t to match a TAB character. So the net behaviour is the same, but the reason for it is different.

See Text Fields for more information on token and slash processing.