hello,
I have a problem matching nested levels of {}, example:

 >>> import re
 >>> text = """
        outer {
                inner1 { ... }
                inner2 { ... }
        }
        simple { ... }
"""


 >>> r = re.compile(r"""
        (       # OPTION1
                .*?     # begin
                \{      # starting {
                        (?: \{.*?\} )*  # inner groups
                \}      # ending }
        )|      # OR
        (       # OPTION2
                .*? { .*? }             # simple group may also happen
        )
        """, re.DOTALL|re.IGNORECASE|re.UNICODE|re.VERBOSE )


 >>> r.findall(text)

 >>> [('', '\n\touter { \n\t\tinner1 { ... }'), ('', ' \n\t\tinner2 { 
... }'), ('', '
  \n\t}\n\tsimple { ... }')]


the regex I currently use stops at the first closing } but what I am 
looking for is a result as:

[
"outer {
                inner1 { ... }
                inner2 { ... }
        }",
"simple { ... }"
]

is something like that possible?

thanks for any hint
chris
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to