How Do I Match Any One of Multiple Choices in a If/Then or Switch Action?

Keyboard Maestro “If Then Else” Action

If Then Else.kmactions (17 KB)

I am trying to use multiple words however it only works with one word. Attached Example.

Any help is appreciated!!

I have tried “” , % * separators with no luck.

The key is to use Regular Expression ("matches") with the alternate match operator | between each string you want to match.

Also, it is easier to use and read your Macro if you use the "Switch/Case" Action rather than multiple "IF/THEN" Actions.

As an example, I wrote the below Macro using your data, but ONLY for the first two cases.
You can add the additional cases as needed.

##Macro Library   [RegEx] How to Match Any One of Multiple Strings [Example]

<a class="attachment" href="/uploads/default/original/2X/c/c1e0a3e96a4cebbe68a566b329c6677b45ed5488.kmmacros">[RegEx] How to Match Any One of Multiple Strings [Example].kmmacros</a> (5.5 KB)



Each Case in the below Switch Action uses Regular Expression (by choosing the "matches" option).
The RegEx pattern uses the vertical bar ("|") to provide for alternate matches, like this:


will match any of the strings.

So, in the below Switch Action, I replaced the SPACE between each word wth a "|":



<img src="/uploads/default/original/2X/8/8800f0de410e42434fa3369cd855a97d11dca16a.png" width="256" height="558">


### Example Results

<img src="/uploads/default/original/2X/3/37ac7896842cf719c7eca2650b34b61377804125.jpg" width="450" height="264">
1 Like

Keith, I hope you don't mind that I changed the Title of your Topic:

FROM: If any of the following are true: Contains execute the following actions
TO: How Do I Match Any One of Multiple Choices in a If/Then or Switch Action?

so that the Title better reflects the content of the Topic, and to make it easier for others to find your topic.

Keith, thanks for uploading your Macro.
However, you uploaded as the Actions in the Macro rather than the Macro itself.

Before you export or share your Macro, be sure to select the Macro in the "Macros" panel before doing so.


This even more then I asked for.

Thank You very much……Im going to work excited thanks to you.


1 Like

Thank you for explaining:
Very valuable, and I've been looking for that.

This topic almost answered my question: Having multiple choices as partial match.

I want to have one shortcut key to trigger actions based on the %ChromeURL%. For now, I have 4 different sites I want to assign specific actions, but I also want to trigger a default action for all other sites.

Is it possible to use multiple choices this way?


You don't need an IF action - just replace it with a Switch action like this:

KM 0 2021-09-30_00-57-45

That actually make alot more sense:) thanks!

1 Like