fork(2) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8.  
  9.  
  10. String s = @"This is a sentence with a name like Mrs. D. Smith and Mr J. Smith in it. This is a sentence with odd spacing. This is one with lots of exclamation marks at the end!!!!This is another with a decimal 10.00 in the middle. Why is it so hard to find sentence endings?Last sentence without a space at the start.";
  11.  
  12. foreach (Match m in Regex.Matches(s, @"(.*?(?<!(?:\b[A-Z]|Mrs?|Dr|Rev|\d))[!?.;]+)\s*"))
  13. Console.WriteLine(m.Groups[1].Value);
  14.  
  15.  
  16. }
  17. }
Success #stdin #stdout 0.08s 34200KB
stdin
Standard input is empty
stdout
This is a sentence with a name like Mrs. D. Smith and Mr J. Smith in it.
This is a  sentence      with odd   spacing.
This is one with lots of exclamation marks at the end!!!!
This is another with a decimal 10.00 in the middle.
Why is it so hard to find sentence endings?
Last sentence without a space at the start.