Guest User

Untitled

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