Variable contains string A, B, C, D?

Hi there,

I want to be able to search a variable for a number of different text strings and if any one is present then perform an action.

So from the example, I want to say if this variable contains the text "PIANO" then click at found image, but I also want it to do the same thing if the variable contains the text "SYNTH". I think it's down to my lack of knowledge of the correct syntax to separate strings! I've got this working fine for one string but can't get it working for multiple strings.

Any help would be much appreciated!

Thank you.

One good approach is to use the Switch or Case action (KM Wiki) with "matches", which means Regular Expressions (KM Wiki).

So, for example, if you want a case which matched "PIANO" OR "SYNTH" then you would use this RegEx:
(?i)PIANO|SYNTH

where (?i) means case insensitive,
and the vertical bar | means a logical OR.

Here's a example macro that should get you started. It is NOT complete, and is NOT intended for production use -- just for educational purposes.

Be sure to put the Cases in the order you want them matched.

##Macro Library   Switch Actions Based on Value of Variable [Example]


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/e/e18015bd5c1cffebbc9eda588ea4369044c9284a.kmmacros">Switch Actions Based on Value of Variable [Example].kmmacros</a> (9.3 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---


<img src="/uploads/default/original/2X/c/c88a571c32247264fe5f53cc28f09a5ade969cea.png" width="541" height="1338">

Questions?

Hi there,

Thank you very much for the reply - I’ve just amended my KM file with:

(?i)PIANO|SYNTH

and it’s works when the condition is “matches” but not when it’s “contains”. The problem is the track names I’m searching are likely to vary a lot. Examples might be “Dark Piano” or “Grand Piano” or “upright piano” or “fizzy synth” or “pluck synth”. So I’m looking for a way to discern keywords in the string and in my head “contains” is the right condition to be using.
Is there a reason why it might not be working?

Thanks in advance!

Yes. Using "contains" is an exact string match. RegEx is something completely different, where the RegEx contains codes telling the system how to make a comparison.

OK, that is a lot different from your original question. In the future please be sure to give us a solid representation of the data you need to work with.

Did you try the macro I gave you with a different TrackName, like "Grand Piano"?
It works for me:

Hi there,

Apologies for not being more specific about what I was trying to achieve. In any case - thank you so much “matches” does do exactly what I need, I just hadn’t run a test with “grand piano” or “any other type of piano” yet. It’s great - thank you so much!