Python regex to find characters inside delimiters
Question: I have a more challenging task, but first I am faced with this issue. Given a
string `s`, I want to extract all the groups of characters marked by some
delimiter, e.g. parentheses. How can I accomplish this using regular
expressions (or any Pythonic way)?

    
    
    import re
    
    >>> s = '(3,1)-[(7,2),1,(a,b)]-8a'
    >>> pattern = r'(\(.+\))'
    >>> re.findall(pattern, s).group()            # EDITED: findall vs. search
    ['(3,1)-[(7,2),1,(a,b)']
    
    # Desire result
    ['(3,1)', '(7,2)', '(a,b)']
    


Answer: Use `findall()` instead of `search()`. The former finds all occurences, the
latter only finds the first.

Use the non-greedy `?` operator. Otherwise, you'll find a match starting at
the first `(` and ending at the final `)`.

Note that regular expressions aren't a good tool for finding nested
expressions like: `((1,2),(3,4))`.

    
    
    import re
    s = '(3,1)-[(7,2),1,(a,b)]-8a'
    pattern = r'(\(.+?\))'
    print re.findall(pattern, s)
    

