Optional Regex Capture Group

Hello People,

Can I have one of you Regex folks help me with a problem I'm having?

I'm trying to have KM tell me a capture Group doesn't exist.

Here is the text:

Ready - Set - Go

I'm using the following Regex to Match the groups (It matches):

(.*) - (.*) - (.*?)$

KM tells me that the last group is Go. Great

However, how to I ask KM to tell me that the last group doesn't exist for the following text and I get nothing/nada/KM won't talk to me:

Ready - Set

Here is the feeble attempt that I've been struggling with.

RegEx Capture Group.kmmacros (4.7 KB)

Macro Screenshot

If someone can put me out of my misery, please do so. It takes a lot for me to ask but I'm at that point.

Thanks much!

This regex looks for the minimum match in each group but includes the delimiter (which is later stripped) from the submenus and looks for an empty variable:

RegEx Capture Group.kmmacros (6.8 KB)

1 Like


Thank you for the quick response and the solid! I'll test once I get back to my Mac. I'm going to mark it as solved because you always come through.

As always, thank you for your knowledge and assistance!


Yes indeed!l! Works lovely! I'll study to see what you did and what I should have done.

Thanks again @mrpasini!


1 Like

I should probably add that if you are actually looking for a Menu option, you might prefer to use the If-Then-Else action's Menu condition, which lets you check for an enabled Menu option of a specific name.

Understood. I've used that technique with other macros. In this case, all the menu items are available and enabled. I have to use different actions for the 2 tier as opposed to the 3 tier menu selection. Your regex guidance made my macro work perfectly.

Thank you @mrpasini


1 Like