I have the following Regex:
public static Regex regex = new Regex( @"(?:\s+(?<statement>(?:[\w./]+)?\s*(?:(?:With|Without)\s*(?:[\w./]+))?)\s*(?:$|\s+AND))+(?<remainder>.*)");
For the string " Tom With Jane AND Mike Without Anne AND" I can capture both "Tom With Jane" and "Mike Without Anne" as statements. Now I'd like to capture the last "AND" in the "remainder" group since it is not followed by another statement. How can I do that? Here's the code that I'm using:
class Program {
public static Regex regex = new Regex( @"(?:\s+(?<statement>(?:[\w./]+)?\s*(?:(?:With|Without)\s*(?:[\w./]+))?)\s*(?:$|\s+AND))+(?<remainder>.*)" );
static void Main( string[] args ) {
var s = " Tom With Jane AND Mike Without Anne AND";
var match = regex.Match( s );
var statements = match.Groups["statement"];
var remainder = match.Groups["remainder"];
}
}