language: C# (mono-2.8)
date: 886 days 0 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Text.RegularExpressions;
 
/*
http://kobikobi.wordpress.com/2010/12/14/net-regex-mathcing-mixed-balanced-parentheses/
*/
 
public class Test
{
        public static void Main()
        {
                string pattern = @"
(
    [^(){}\[\]]+
    | \( (?=[^)]*  (?<Stack> \) ) )
    | \[ (?=[^\]]* (?<Stack> \] ) )
    | \{ (?=[^}]*  (?<Stack> \} ) )
    | \k<Stack> (?<-Stack>)
)+?
(?(Stack) (?!))
";
                string text = Console.ReadLine();
                MatchCollection matches = Regex.Matches(text, pattern,
                        RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
                foreach (Match match in matches)
                {
                   Console.WriteLine(match.Value);
                }
        }
}
  • upload with new input
  • result: Success     time: 0.04s    memory: 37224 kB     returned value: 0

    (2)({1}2[3(4)5]6){{}{{}}[()]}
    (2)
    ({1}2[3(4)5]6)
    {{}{{}}[()]}