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> { "[45645]","[5456]","[PB15] [DEC]","[PB16] []"};
  12. foreach (var str in strs) {
  13. var result = Regex.Matches(str, @"\[[^][]+]")
  14. .Cast<Match>()
  15. .Select(x => x.Value)
  16. .Where(m => m.Any(Char.IsDigit))
  17. .ToList();
  18. foreach (var s in result)
  19. Console.WriteLine(s);
  20. }
  21. }
  22. }
Success #stdin #stdout 0.05s 134848KB
stdin
Standard input is empty
stdout
[45645]
[5456]
[PB15]
[PB16]