# read a file up to a certain header and extract just the part between matching curly braces pair after it
# default braces are { but it can be provided as argument
#
# curlies.py <regex to match to start parsing> [<opening brace> <closing brace>]
#
# Copyright (c) 2016-, Juniper Networks, Inc.
# All rights reserved.

import re
from sys import argv
from sys import stdin

started = False
depth = 0
lines = 0

p = re.compile(argv[1])

ob = "{"
cb = "}"

if len(argv) > 2:
    ob = argv[2]
    cb = argv[3]
    pass

# print ob,cb

for line in stdin.readlines():

    lines += 1

    if p.match(line) is not None:
        # print "matched", line
        started = True
        pass

    if started:

        if ob in line:
            depth += 1
        pass
        if cb in line:
            depth -= 1
            if depth == 0:
                started = False
                pass
            pass
        pass

        if depth > 0:
            print (line.rstrip())
            pass
    pass
