The regex (?<=[\.\!\?]\s[A-Z])
almost works after being tested, buts it sadly leaves the capital letter in the pervious match. A fix to this would be taking that letter and removing it from the previous match while adding it back to the match itself.
Example:
//the string
string s = "The fox jumps over the dog. The dog jumps over the fox.";
string[] answer = Regex.Split(@"(?<=[\.\!\?]\s[A-Z])");
Console.WriteLine(answer);
The output would be: ["The fox jumps over the dog. T","he dog jumps over the fox."]
To fix this:
//make sure there is a split
if (lines.Length > 1)
{
for (int i = 0; i < lines.Length; i++)
{
//store letter
char misplacedLetter = lines[i].TrimEnd().Last();
//remove letter
lines[i] = lines[i].Substring(0,lines[i].Length-1);
//place on front of next sentence.
lines[i + 1] = misplacedLetter + lines[i + 1];
}
}
This worked for me well. (you may chose to cache lines[i]
instead of accessing it over and over)