fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string[] strings = {
  9. "%some_text%",
  10. "%some[_]te_t[%]"
  11. };
  12.  
  13. foreach (String s in strings) {
  14. var result = Regex.Replace(
  15. s,
  16. @"\[([%_])\]|([%_])", match =>
  17. match.Groups[2].Success ? "*" : match.Groups[1].Value
  18. );
  19. Console.WriteLine(result);
  20. }
  21. }
  22. }
Success #stdin #stdout 0.09s 21088KB
stdin
Standard input is empty
stdout
*some*text*
*some_te*t%