Replacing text under certain conditions

For some reason I always mistype "?" with ">". Some deep grained muscle memory - odd I know.

What I want to do is replace ">" if it has text immediately to the left but to leave it alone if not.

So "What do you think>" Would be "What do you think" but it would not swap "what > do you > think" due to the spaces.

Is that possible?

Sure. Try this. If you type a space before the >, you get the > but if you type a character before it, you get a question mark. Depending on your text, the regexp could use some refinement.

This is how autocorrection works in general. The error triggers the correction.

Keyboard Maestro 8.2.4 “cx: > for ?” Macro

cx- > for ?.kmmacros (1.7 KB)

1 Like

That worked!

Is there any way to add exceptions? i.e. do this always unless charter to the left is "-" or


Yep, that would be the "refinement" I mentioned. Try changing the \S> to \b> to 1) avoid deleting the first of the two characters and 2) using '>' after a hyphen.

Use a negative look-behind assertion

Something like:


That means: match > unless the immediate preceding character (which is not included in the match) is a letter or digit.


Very grateful for the help thanks!