How to ignore portions of a Variable using RegEx?

How can I omit a character string in the middle of a variable using RegEx?

Specifically, I need to delete all characters between "Ring" and "[Metal Type]" in the following examples:

Ring - 8mm - Flat - 9 - White Gold - FingerPrint
Ring - 7mm - Flat - 8 - Stainless Steel - FingerPrint
Ring - 6mm - Half-Round - 8 - Rose Gold - FingerPrint

I'm trying to match a "Product" variable to a generic "Template" file using a "Switch" action and don't care about the width, profile & size info contained in the "Product" name (see screen image):

This is specific to the ring products. All other product names correspond directly to the template name.

Thanks for any help.

Just use the "matches" operator in the Switch Action:

For example:
(?i)^Ring.+Stainless Steel

image

I’d be lost without your help and the help of others on this forum. Thank you!

Is this something I can learn from the KM Wiki, or do I just need to study RegEx online?

I also notice you used a “Local” variable. Since I may be capturing the variable in a separate macro from the “Switch” macro, will it still work to use a Local variable? I need to learn more about their advantages.

The KM Wiki offers some help for RegEx:
Regular Expressions

but to learn it I recommend
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns

and make good use of RegEx101.com to develop, text, and see detailed explanation of RegEx patterns.

Local Variables persist ONLY for the duration of the Macro in which they are created. So, you will need to use a global variable, which is any variable that does NOT start with "Local" or "Instance".

I use this naming convention for global variables:
DND_<MasterPrefix>__<VariableName>

where

DND            -- stands for Do Not Delete
<MasterPrefix> -- a short 3-4 character prefix which associates that variable with 
                  a specific macro, or set of macros.
                  This usually comes from the first 3 words of the Macro Name.
<VariableName> -- Identifies the specific variable.  I use CamelCase.

This naming convention allow me to easily:

  1. Identify all global variable that MUST NOT be deleted
  2. Identify all variables associated with a specific macro or set of macros
  3. Avoid unintended reuse of the same variable name in different macros, overwriting data that it should not.
  4. Use of the double underline removes the entire prefix from display in Prompt for User Input Actions

Each of use may have our own naming convention. Pick one that works for you, and stick with it.

So, in your use case, I would probably name the "Local__Product" variable as:
DND_PJO__Product

where "PJO" is my made-up prefix for "Process Jewelry Orders"

1 Like