How to Use OR to Match Multiple Options on the Clipboard?


How to achieve ''OR'' expression?

Here is my macro. I want to test if clipboard contains any of a set of words such as: ''red'' or ''green'' or ''blue''.

How does Keyboard Maestro do alternation?


I'm just getting started with KM myself but this is how I would check to see if the system clipboard contains red or green or blue.


There are other ways that you could accomplish the same thing but this is a simple built in way to do it using the If any action block.


That's a nice way, and easily understood when you go back to it later.

You can also use a Regular Expression via the "matches" condition, where the | (pipe) character means "or". For a case sensitive match:

And for case-insensitive matching you priced the expression with (?i):

Spaces count when trying to match -- red|green|blue is not the same as red | green | blue -- so watch out for that!


Nice. regex was the other way I was thinking but I hadn’t done it that way before. I like that.

thanks Nige, This is what I need!

thanks, Mike, I also use this way at the beginning, but I find it needs lots of time if the words are too many need to match,

If you've got a lot of words there may be a better, and more easily maintained, way of doing what you want. If you explain your workflow and want you want to achieve you may get some better suggestions!

1 Like