def decimal_function(number):
    """
    It converts a binary number into a decimal number by using
    a re and a recursion function.
    """

    decimal_sum = 0
    #regular expression substitution
    transform = re.sub("(]?\w+)(\w{1})", '\g<1>.\g<2>',str(number))

    for arg in str(number):
        
        if  arg[0] != '-' and arg != '.' and int(arg) != 0 and int(arg)!= 1 :
            raise TypeError,\
              "\n<binary numbers should be composed of 0 and 1 digits only "
     
    try:   
        # recursion base case
        if number == transform:
            for item in xrange((len(number)-1)/2,-2,-1):
                for res in xrange(0,len(number)):
                    if transform[res].isdigit():
                        next_item = 2**item * int(transform[res])
                        item -= 1
                        decimal_sum += next_item

                return decimal_sum
        else:
            if number > 0:
                return decimal_function(transform)
        
            else:
                return decimal_function(transform)*-1
            
    #Raise TypeError if input is not a binary number          
    except TypeError,exception:
        print exception

    It converts a binary number into a decimal number by using
    a re and a recursion function.
    
recipes/Python/577034_BinaryDecimal_Recursion/recipe-577034.py