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> { "123", "(1234)", "1", "(33)", "(123", "123)"};
  12. var rx = new Regex(@"^(?<bracket>\()?\d+(?(bracket)\))$");
  13. foreach (var s in strs)
  14. Console.WriteLine($"{s} => {rx.IsMatch(s)}");
  15. }
  16. }
Success #stdin #stdout 0.05s 19528KB
stdin
Standard input is empty
stdout
123 => True
(1234) => True
1 => True
(33) => True
(123 => False
123) => False