Guest User

Untitled

a guest
May 17th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. using System;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var text = "123456789";
  12. var res = Regex.Replace(text, @"^((?<ch>.)*).((?<-ch>.)*(?(ch)(?!))$)", @"$1$2");
  13.  
  14. Console.WriteLine(text);
  15. Console.WriteLine(res);
  16. }
  17. }
  18.  
  19. string input = "aaa bbbb ccccc dddddd";
  20. string pattern = @"w+";
  21. string RemoveCentralSymbol(string s) => s.Remove(s.Length / 2, s.Length % 2);
  22. var result = Regex.Replace(input, pattern, match => RemoveCentralSymbol(match.Value));
  23. Console.WriteLine(result);
Add Comment
Please, Sign In to add comment