fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public static class Test
  8. {
  9. public static void Main()
  10. {
  11. var s = "A Borrower (or the Parent) may not deliver a Utilisation Request if as a result of the proposed Utilisation:<br/>[10] or more Term Loans [(other than Incremental Company Loans)] would be outstanding; [or]<br/>[15] or more Revolving Company Utilisations would be outstanding[; or<br/>[20] or more Incremental Company Loans would be outstanding].<br/>A Borrower (or the Parent) may not request that a Company A Loan [or an Incremental Company Loan] be divided if, as a result of the proposed division, [ 25 ] or more Company A Loans [or [ 50 ] or more Incremental Company Loans] would be outstanding.<br/>[A Borrower (or the Parent) may not request that a Company B Loan or a Company C Loan be divided.]";
  12. var result = s.Split(new[] {"<br/>"}, StringSplitOptions.None)
  13. .SkipWhile(x => !x.Contains("other than Incremental Company Loans"))
  14. .MagicTakeWhile(x => !x.EndsWith(".") && !x.EndsWith(";"));
  15. Console.WriteLine(string.Join("\n", result));
  16. }
  17. public static IEnumerable<T> MagicTakeWhile<T>(this IEnumerable<T> data, Func<T, bool> predicate) {
  18. foreach (var item in data) {
  19. yield return item;
  20. if (!predicate(item))
  21. break;
  22. }
  23. } // Reference: https://stackoverflow.com/a/11883524/3832970
  24. }
  25.  
Success #stdin #stdout 0.01s 132544KB
stdin
Standard input is empty
stdout
[10] or more Term Loans [(other than Incremental Company Loans)] would be outstanding; [or]
[15] or more Revolving Company Utilisations would be outstanding[; or
[20] or more Incremental Company Loans would be outstanding].