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?
"Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch
Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch
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).
- 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
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!
Feel free to leave a comment on the Appstore!
- 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
Like Thomas said here, the fastest way out would be using string splitter app, as it requires no code.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.
Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch
I second String Splitter, it's a great app!
Color Science & Workflow Automation
Re: "Regex Help: How to Extract First PANTONE Color Before Semicolon in Switch
I could also offer this RegEx:
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.
Code: Select all
(?i)([^;]*\bPANTONE\b[^;]*)
[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.