fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class RegexExample
  5. {
  6. public static void Main()
  7. {
  8. var text = "ThisStringHasNoSpacesASCIIButItDoesHaveCapitalsLINQ";
  9.  
  10. // Use positive lookbehind to locate all upper-case letters
  11. // that are preceded by a lower-case letter.
  12. var patternPart1 = "(?<=[a-z])([A-Z])";
  13.  
  14. // Used positive lookbehind and lookahead to locate all
  15. // upper-case letters that are preceded by an upper-case
  16. // letter and followed by a lower-case letter.
  17. var patternPart2 = "(?<=[A-Z])([A-Z])(?=[a-z])";
  18.  
  19. var pattern = patternPart1 + "|" + patternPart2;
  20. var rgx = new Regex(pattern);
  21. var result = rgx.Replace(text, " $1$2");
  22.  
  23. Console.WriteLine("Input: [{0}]\nOutput: [{1}]", text, result);
  24. }
  25. }
  26.  
Success #stdin #stdout 0.07s 34152KB
stdin
Standard input is empty
stdout
Input: [ThisStringHasNoSpacesASCIIButItDoesHaveCapitalsLINQ]
Output: [This String Has No Spaces ASCII But It Does Have Capitals LINQ]