fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var strs = new List<string> { "*10.18).xlsx", "*(23.10.18).xlsx" };
  12. var block = @"[][+&|!(){}^""~?: \\/-]";
  13. var rx = new Regex($@"(\*)({block}?)|{block}");
  14. foreach (var str in strs) {
  15. string reg = "id:" + rx.Replace(str, m =>
  16. m.Groups[1].Success ? $"*\\{m.Groups[2].Value}" : $"\\{m.Value}");
  17. Console.WriteLine(reg);
  18. }
  19. }
  20. }
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
id:*\10.18\).xlsx
id:*\(23.10.18\).xlsx