fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string pattern = @"(?<=^(?:[^$]*\$){0,3})[^$]*\$?|[^$](?=\$|$)";
  10. string[] strings = {
  11. "Text1",
  12. "Text1$Text2$Text3",
  13. "Text1$Text2$Text3$Text4$Text5$Text6"
  14. };
  15.  
  16. Regex regex = new Regex(pattern);
  17.  
  18. foreach (String s in strings) {
  19. Console.WriteLine(string.Join("", from Match match in regex.Matches(s) select match.Value));
  20. }
  21. }
  22. }
Success #stdin #stdout 0.06s 21820KB
stdin
Standard input is empty
stdout
Text1
Text1$Text2$Text3
Text1$Text2$Text3$Text4$56