fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string fullText = @"Borrower: Guarantor:
  9. {{0_SH}} By: {{1_SH}} (seal)
  10. By: (seal)
  11. Print Name:
  12. Print Name:
  13. Phillip Moore Phillip Moore
  14. Date: {{1_DH}}
  15. 2/23/2022
  16. Title: Owner
  17. Date: {{0_DH}}
  18. 2/23/2022
  19. 12 of 12 (LOC 2020) Borrower Initials {{0_IH}}
  20.  
  21. Borrower: Guarantor:
  22. {{0_SH}} By: {{1_SH}} (seal)
  23. By: (seal)
  24. Print Name:
  25. Print Name:
  26. Phillip test Moore Phillip test Moore
  27. Date: {{1_DH}}
  28. 2/23/2022
  29. Title: Owner
  30. Date: {{0_DH}}
  31. 2/23/2022
  32. 12 of 12 (LOC 2020) Borrower Initials {{0_IH}}";
  33. string pattern = @"\bPrint\sName:\r?\n(?!Print\sName)(?'guarantor1'[a-zA-Z\s',.&\d\--]+?)(?= \1\r?$)";
  34. Regex rgx = new Regex(pattern, RegexOptions.Multiline);
  35. MatchCollection matches = rgx.Matches(fullText);
  36. if (matches.Count > 0)
  37. {
  38. string guarantor1 = matches[0].Groups["guarantor1"].Value;
  39. Console.WriteLine(guarantor1.Trim());
  40. }
  41. }
  42.  
  43. }
Success #stdin #stdout 0.08s 29372KB
stdin
Standard input is empty
stdout
Phillip Moore