How to capture variables from Tab-delimited variable with varying number of tabs?

I have a RegEx search script that captures variables from a 6-Tab variable. I need to expand it to capture variables for up to 8 tabs. How can I write the RegEx so it works for either 6 OR 8-tab text objects?

Actions (v9.0.6)

Keyboard Maestro Actions.kmactions (1.9 KB)

This shows the result of searching a 6-tab chart. Obviously just adding tabs to the RegEx does not work. I would simply add additional blank tabs to the "template files" these are pulled from but there are more than 100 charts. There's probably a better way.

Here's a sample tabbed "Coordinates Chart" that is saved into the "Coordinates" variable for parsing:
R1_C1 -45.25 -27.00 12.05 25.63 12.05 25.95 12.05 25.63
R1_C2 -17.55 -27.00 35.35 25.63 12.05 25.95 12.05 25.63
R1_C3 6.08 -27.00 58.65 25.63 12.05 25.95 12.05 25.63
R1_C4 29.62 -27.00 81.95 25.63 12.05 25.95 12.05 25.63
R2_C1 -41.18 5.50 105.20 25.63 12.05 25.95 12.05 25.63
R2_C2 -17.58 5.50 12.00 62.23 12.05 25.95 12.05 25.63
R2_C3 5.90 5.50 35.40 62.23 12.05 25.95 12.05 25.63
R2_C4 29.50 5.50 58.60 62.23 12.05 25.95 12.05 25.63
R3_C1 -41.30 37.90 81.85 62.23 12.05 25.95 12.05 25.63
R3_C2 -17.75 37.90 105.10 62.23 12.05 25.95 12.05 25.63
R3_C3 5.85 37.90 12.20 98.93 12.05 25.95 12.05 25.63
R3_C4 29.50 37.90 35.45 98.93 12.05 25.95 12.05 25.63

Thanks for any insights on this.

I've done almost exactly this technique with no problem if the regex is searching for more delimiters than are actually there. It simply doesn't update the variables corresponding to the remaining (unfound) capture groups. Does that not work for you?

Hmm… When I do all the variables remain blank (See variable 1).

Thanks for the response. Hopefully a small RegEx tweak will make it work.

Isn’t that because your capture groups are capturing the tabs as well? Have you tried (.*?) instead of (.*) for your capture groups?

Or ([^\t]*) ( i.e. not tab)?

Yeah, I got excited too soon. That actually failed. I'll try your new one.

But don't I need the tab to identify the breaks?

Yes, between the capture groups, but not in them.

Right, that's how my original search was.

Also, have you tried just setting the 8 tab action to not cancel on failure? That way, if there are 8, the first one will load 6, but the second one will reload all 8. If, on the other hand, there are only six, then the first will load those 6, and the second will just fail and proceed to the next action.

1 Like

That's a great thought. I was looking for a way to determine how many Tabs were in a line and run one or the other. Putting them in-line would be simpler.

That works! Sure appreciate the help.

Neato. You're quite welcome.

By the bye, for others out there, this technique would work for any number of alternatives, as long as you order the regex actions from shorter to longer, as the 6-tab action before the 8-tab action in this example. All of the alternatives after the first (shortest) should be set to NOT cancel on failure.

1 Like