Easier, I find, to think in terms of producing an additional derived variable (pruned), rather than delete-mutating the unfortunate existing variable (in place) – that is a quickish route to mishap and puzzlement.
(You can always clear all temporary variables at the end)
Please always provide a working sample macro – this will greatly facilitate anyone who wants to help you – and make it much more likely that someone will.
Although it is sometimes possible to tell on cursory examination what is wrong with a macro, it is generally necessary to actually test it in action to properly debug it.
It took me 5+ minutes to recreate your macro, and I can't be certain I got all the fiddly bits of the regular expression correct.
Nevertheless – using your sample string I got a correct answer the first time – even though your regex is a bit off:
A) You don't have to escape spaces in a regular expression.
B) (<your_pattern>)+ shouldn't be necessary.
– I.E. the parentheses and the outer + sign
– What were you trying to accomplish?
Do you have BBEdit? It makes creating and debugging regular expressions easier than fooling with them directly in Keyboard Maestro.
(Even the free version is much more powerful than TextWrangler used to be.)
You can use the Live Search function to create a regular expression live and see it work – much as you can with the Regex101.com site – but without all the distractions. (I also use an app from the app-store called Patterns for this – and an app called RegExRx – but I always start with BBEdit.)
Now then – you're aware that when you use Local variables they are DEAD as soon as the macro completes? (This can unexpectedly affect actions that display action results inline.)
If you want to see local variable contents you need to use a Display Text action or another mechanism.
I usually don't develop macros using local variables, because it makes debugging more difficult. I only change variables to local after I've got a macro working.
I'm nearly always sorry if/when I break that rule...
We potentially have 100's of "ring" product names because of multiple sizes. Since the size is irrelevant to the template choice, it is necessary to strip it out of the variable. RegEx does that nicely. The "IF/THEN" action is to handle "Ring" products separately from other products which will be used as they are captured.
I really think I have a working solution now. Moving it from a "Switch" action to searching an external .txt file make a WORLD of difference in editing.
One more question: I'm maintaining the Text file in Google Sheets. When I export the page it saves in ".TSV" format. I was initially changing the extension to ".TXT" which works. I've since realized KM recognizes the "TSV" as well. Is there any reason not to just access it as a ".TSV" file in KM?