Places where Regular Expressions can be used

I was reminded recently that there are Action fields where you can specify a regex by preceding match text with “^”. I can’t find the post, but in it even @peternlewis admitted he had forgotten you could do it in that particular instance.

That led me to a couple of thoughts:

  1. I wish the Action Editors would mention it somehow - indicate that you could use a regex by including “^” at the start. Not sure how it would be worded or decorated, but still…

  2. If it doesn’t already, the Wiki should mention it prominently everywhere it can be used. Please forgive me if it already does, and please point me to it. Otherwise, if we could get a list of those Actions, I’d be willing to update the Wiki.

Normally when I post something like this, someone points out that these things already exist. I hope this is another one of those cases. :slight_smile:

1 Like

I'm not sure I understand. (what's new? LOL)

Anywhere the Action offers a choice of "match", then that is the keyword/indicator that you can use RegEx. A prefix of "^" is not required. It simply means "at the start of the string to be evaluated", as I'm sure you know.

For example:


Are you suggesting there are other Actions where there is no indication of availability of RegEx (i.e. no "match", "matching", or "Regular Expression" is shown) that it is possible to use RegEx? If so, can you please provide an example?

Yes. Here is an example:

https://wiki.keyboardmaestro.com/action/Press_a_Button?s[]=press&s[]=button

Of course, the Wiki for this example does mention it. :slight_smile:

Now that I understand what you are asking for, then I think this choice (#2) is a good one, and one that is easily implemented.

What don't we use this topic to list Actions that can use RegEx, but neither the Action nor the Wiki so indicates. Then, any of us wiki editors, can updated the Wiki accordingly.

Your thoughts?

Sounds good.

By the way, I couldn’t find that example by searching the Wiki. I thought I searched for “regular expressions”, so I wonder if we need to do something special to make it be a hit? Honestly, I don’t know much about how Wiki searches work.

The Wiki search does NOT handle singular/plural terms well, if at all. So you have to search for both.

I did this search:
https://wiki.keyboardmaestro.com/Home_Page?do=search&id=regular+expression

and it found a bunch, including these at the bottom of the search results:
(Press a Button is near bottom)

OK, cool. Then I just need to learn to do better searches. Thanks.

In almost all cases, regex is signified explicitly, usually by a menu selection that allows “matches” as an option, or for some actions like Search Variable it is always a regex.

But there are a few cases where a text field is almost always just a “contains” or “is” test (eg Button Press), and in some of those I allow regex if the entry starts with “^”.

I believe the only two cases of this are button matching and menu matching. It looks like button matching only applies to Press Button action, but menu matching probably applies to most menu matching facilities (like the menu condition).

1 Like