For Each Action Only Finding First Substring

I thought these actions previously worked to loop through and process each substring. However, I don't recall making any changes, but I'm not 100% certain it has worked since upgrading to Keyboard Maestro 10.0.1 on macOS 11.6.1 either. I'm having difficulties debugging why the remaining substrings or Release_Item(s) are not found and would appreciate some suggestions to check. It is probably something obvious that I'm missing since Regex101.com appears to capture each Release_Item, but the For Each action only captures the first substring.

The ReleaseItem_Data variable contains:

⌘$H$115⌘4⌘SUNBELT RENTALS⌘RENTAL OF MANLIFT 10/19 - 10/20 ⌘$860.37⌘FALSE⌘$H$116⌘4⌘NEXAIR⌘NITROGEN CYLINDERS QTY 12 & 16 CYLINDER SKIDS⌘$1,073.42⌘TRUE⌘$H$117⌘4⌘NEXAIR⌘PRESSURE REGULATOR 5-550 PSI⌘$543.10⌘FALSE⌘$H$118⌘4⌘AMERIGAS⌘534.7 GAL/ PROPANE⌘$967.98⌘FALSE

The substring capture regex is:

^\⌘(\$[A-Z]\$\d+)\⌘(\d{1,2})\⌘(.*?)\⌘(.*?)\⌘(\$?[0-9]+[\d,]*[\.]?[\d]*)\⌘(TRUE|FALSE)

For Each.kmactions (65 KB)

Keyboard Maestro Export

Your regex to break up the data into substrings starts out with ^ which anchors it to the beginning of the string. Only the first match at the beginning of Data will match it. Remove the ^ at the beginning and it may work. May because when I did that, I only matched the first 2 strings. I think there is something wrong in your regex (or my typing of it) that caused the last one to mismatch.

It might be better to use a regex like this:

⌘\$[A-Z]\$\d+⌘\d+⌘[A-Z ]+⌘[A-Z0-9/\-\. ]+⌘\$[0-9\.]+⌘(TRUE|FALSE)

That matched all 3 strings for me. It doesn't try to be as precise as yours so it may not actually work for you. Couple of things I noticed:

You don't have to escape every "weird" character, I've been finding lately if I do this it breaks the regex. So the ⌘ doesn't need to be \⌘

I removed the grouping parentheses as they aren't used for anything in this particular regex (it worked with them in just the same).

I see you're using [0-9] in some places so I assume you know that means any character in the range of, but you can stack as many additional characters into the brackets as you want and it'll work as "find one of any of these characters) so where I do [A-Z0-9/-. ]+ that means any upper case letter, any digit 0 to 9 the forward slash, the dash (has to be escaped) the period (also escaped), or a space.

Hey @KM_Panther,

When posting something like this please:

  • Use the preformatted-text button in the forum editor to post text that needs to be seen verbatim (not rendered by the browser) – like data and regex patterns.
  • Post a complete macro rather than a set of actions.
  • Provide the data IN your macro, so helpers don't have to fight with it.

I have fixed your original post.

It looks like Steve has solved your issue.

Take Care,
Chris

(Keyboard Maestro Moderator)

I have retracted a confusing post

In my initial posting, I indicated that I "thought" this action worked previously. In fact, I know it has worked previously for a long time and I have not modified this macro and have used it for some time. It is a very long macro and I thought it was not useful to post the other unrelated actions, but I will include full macros when requesting support in the future.

Thanks for the instruction on posting text that needs to be seen verbatim and the regex recommendations for the resolution of my issue. As suggested, removing the caret (^) enabled the For Each action to loop through each substring. Still not sure what changed.

Don't do that unless it's really necessary.

When possible post the smallest possible test case that demonstrates your issue.

In this case you only needed to copy what you posted into a new macro and add a data variable.

Everything after the search action could be removed and replaced with a display text action that displayed the found variables.

Short, sweet, and easy to test.

Keep in mind – the easier you make it for others to TEST your work – the more likely you'll get timely and quality help.

Trying to debug macros by eye is largely a waste of time. We need to test.

-Chris