def count_patterns(regex):
    """
    >>> count_patterns('foo: \\d')
    0
    >>> count_patterns('foo: (\\d)')
    1
    >>> count_patterns('foo: (\\d(\\s))')
    1
    """
Find out number of capture groups in Python regular expressions