Implement a function/class, which should return an integer if the input string is in one of the formats specified below, or `null/nil/None` otherwise.
Format:
* Optional `-` or `+`
* Base prefix `0b` (binary), `0x` (hexadecimal), `0o` (octal), or in case of no prefix decimal.
* Digits depending on base
Any extra character (including whitespace) makes the input invalid, in which case you should return `null/nil/None`.
Digits are case insensitive, but base prefix must be lower case.
See the test cases for examples.
import re
def to_integer(string):
    b = r'\A[+-]?0b1+[01]*\Z'
    x = r'\A[+-]?0x[1-9A-Fa-f]+[0-9A-Fa-f]*\Z'
    o = r'\A[+-]?0o[1-7]+[0-7]*\Z'
    d = r'\A[+-]?[0-9]+\Z'
    #print(string)
    for pattern, base in zip((b,x,o,d), (2,16,8,10)):
        if re.search(pattern, string):
            return int(string, base)
    return None
import re
def to_integer(string):
    b = r'\A[+-]?0b1+[01]*\Z'
    x = r'\A[+-]?0x[1-9A-Fa-f]+[0-9A-Fa-f]*\Z'
    o = r'\A[+-]?0o[1-7]+[0-7]*\Z'
    d = r'\A[+-]?[0-9]+\Z'
    #print(string)
    for pattern, base in zip((b,x,o,d), (2,16,8,10)):
        if re.search(pattern, string):
            return int(string, base)
    return None