Good way to select delimiter and everything else to the next delimter with regex?

First time posting on StackOverflow for me. Please go easy on me :) I am trying to parse a complex string with Regex. I have gotten close to my desired results but not quite to the finish line.

I have listed a couple example strings below. These strings change in length and verbiage when they are generated.

I want to grab the charge class (FGM)(Felony, General, Misdemeanour), all the way to the next occurrence of (FGM). This should essentially split the string every time there is a new charge.

Here is the regex that has gotten me the closest:


Example String:

F  -  Bond/Bail Set  -  609.342.1(b)  Criminal Sex Conduct-1st Degree-Penetration-V  F  -  Bond/Bail Set  -  609.344.1(b)  Criminal Sex Conduct-3rd Degree-Victim 13-15 F  -  Bond/Bail Set  -  609.344.1(c)  Criminal Sex Conduct-3rd Degree-Force or Coer  F  -  Bond/Bail Set  -  609.748.6(d)(6)  Harassment; Restraining Order - Violate - Vic  F  -  Bond/Bail Set  -  609.748.6(d)(6)  Harassment; Restraining Order - Violate - Vic

My Regex:

My Regex

It's pretty close, but it's grabbing too much. It should stop at the next occurrence of F G M (Felony, General, Misdemeanour) as shown in the image below.

Correct Regex

Correct Regex

Does anyone know of a way to accomplish this with regex?

Read more here:

Content Attribution

This content was originally published by Vyqnk5A4q4sYTt at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: