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 str = "testteststete(segment1)tete(segment2)sttes323testte(segment3)eteste";
  12. var rx = @"\([^)]*\)";
  13. var matches = Regex.Matches(str, rx).Cast<Match>().Select(p => p.Value).ToList();
  14. var result = matches != null && matches.Count > 1 ? matches[1] : string.Empty;
  15. Console.WriteLine(result);
  16. }
  17. }
Success #stdin #stdout 0.1s 24768KB
stdin
Standard input is empty
stdout
(segment2)