Page 1 of 1

"Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch

Posted: Tue Jul 23, 2024 1:34 am
by jcarden
Hi everyone,

I'm struggling with configuring a regular expression in Enfocus Switch and need some expert advice. I need to extract the first PANTONE color listed in a string, stopping at the first semicolon. Here’s an example of the string I’m working with:

PANTONE Bright Red C;PANTONE Dark Blue C;PANTONE Pink C;PANTONE Yellow PY12 C

From this string, I only want to select "PANTONE Bright Red C", however that would change for each job...

I tried to use ChatGPT to help write the code, but I it almost always returned ";;;;" instead of the exact text I wanted.

any thoughts?

Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch

Posted: Tue Jul 23, 2024 8:07 am
by freddyp
Each string variable can be modified with After, Before, Segment, Search. In this case Before ; is the obvious approach (Before is before the first occurrence, After is after the last occurrence).

Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch

Posted: Tue Jul 23, 2024 10:37 am
by tdeschampsBluewest
You could also use the app string splitter if you want to access other index of the list with ease.

Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch

Posted: Tue Jul 23, 2024 1:33 pm
by Soul Forge
tdeschampsBluewest wrote: Tue Jul 23, 2024 10:37 am You could also use the app string splitter if you want to access other index of the list with ease.
Like Thomas said here, the fastest way out would be using string splitter app, as it requires no code.

Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch

Posted: Wed Jul 24, 2024 3:27 pm
by rhd_ole
I second String Splitter, it's a great app!

Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch

Posted: Fri Mar 07, 2025 1:04 pm
by yosimo
I could also offer this RegEx:

Code: Select all

(?i)([^;]*\bPANTONE\b[^;]*)
Explanation:

[1] (?i) → Activates case insensitivity (so that “pantone”, “Pantone”, etc. are also found).

[2] ^ → Starts the search at the beginning of the character string.

[3] ([^;]*\bPANTONE\b[^;]*) → Searches for the first expression that:

      [^;]* → contains no semicolons (before the first ; ).

      \bPANTONE\b → The word “PANTONE” (in any spelling) contains.

      [^;]* → “PANTONE” may be followed by any characters except ; .


As the regular expression is not greedy (no .* over the entire character string), it stops after the first matching expression.