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

Post Reply
jcarden
Newbie
Posts: 18
Joined: Sun Feb 26, 2023 5:09 am

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

Post 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?
freddyp
Advanced member
Posts: 1109
Joined: Thu Feb 09, 2012 3:53 pm

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

Post 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).
User avatar
tdeschampsBluewest
Member
Posts: 114
Joined: Tue Jun 01, 2021 11:57 am

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

Post by tdeschampsBluewest »

You could also use the app string splitter if you want to access other index of the list with ease.
Do you like the Enfocus Apps developed by Bluewest?
Feel free to leave a comment on the Appstore!
User avatar
Soul Forge
Member
Posts: 58
Joined: Wed Jul 12, 2023 5:25 pm

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

Post 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.
rhd_ole
Member
Posts: 149
Joined: Mon Jan 24, 2022 5:36 pm

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

Post by rhd_ole »

I second String Splitter, it's a great app!
Color Science & Workflow Automation
yosimo
Member
Posts: 60
Joined: Tue Mar 27, 2018 6:25 pm

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

Post 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.
Post Reply