function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jerun JoseJerun Jose 

Regex to match only till first occurence of class match

I'm looking to construct a regex which will help me identify the first occurrence of a match.

My current regex is "(.*)[Cc][Aa][Ss][Ee][^a-zA-Z\\d]*(\\d\\d*)[^a-zA-Z\\d]*(.*)"

 

What I am trying to do is to find if the input string contains the word "case" (case insensitive), followed by any number of special characters, followed by a number; I want to retrieve 3 parts of the text.

 

Say my input string is "RE: FW: case:-1234: there is some description"

Using this regex, I am able to retrieve, "RE: FW: ", "1234", "there is some description".

 

This is fine, but if my input string is "RE: FW: case:-1234: This is in reference to case 789 reopening"

 

Then my regex returns, "RE: FW: case:-1234: This is in reference to", "789", "reopening".

 

What I would like to get is "RE: FW: ", "1234", "This is in reference to case 789 reopening".