fork(1) download
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7.  
  8. public class Test
  9. {
  10. public static void Main()
  11. {
  12. var s = "Hi is this available 18dec to 21st dec 2nd dec 1st jan dec12th";
  13. var res = Regex.Replace(s, @"(\p{L})?(\d+)(st|[nr]d|th|(\p{L}+))", repl);
  14. Console.WriteLine(res);
  15. }
  16. public static string repl(Match m)
  17. {
  18. var res = new StringBuilder();
  19. res.Append(m.Groups[1].Value);
  20. if (m.Groups[1].Success)
  21. res.Append(" ");
  22. res.Append(m.Groups[2].Value);
  23. if (m.Groups[4].Success)
  24. res.Append(" ");
  25. res.Append(m.Groups[3]);
  26. return res.ToString();
  27. }
  28. }
Success #stdin #stdout 0.04s 134336KB
stdin
Standard input is empty
stdout
Hi is this available 18 dec to 21st dec 2nd dec 1st jan dec 12th