fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string pattern = @"([^\s,]+),\s*([^\s,]+(?:, CPA, CFA)?)$";
  9. string input = "John, Jan, Joe\nJohn, Jan, Joe, CPA, CFA\njake, jan, joe, john, jessie, jack, jones";
  10. Console.WriteLine(Regex.Replace(input, pattern, @"$1 and $2", RegexOptions.Multiline));
  11. }
  12. }
Success #stdin #stdout 0.08s 29372KB
stdin
Standard input is empty
stdout
John, Jan and Joe
John, Jan and Joe, CPA, CFA
jake, jan, joe, john, jessie, jack and jones