Decode single hex/unicode escapes found in regex matches.

    Supports single hex/unicode escapes of the form ``'\\xYY'``,
    ``'\\uYYYY'``, and ``'\\UYYYYYYYY'`` where Y is a hex digit. Only
    decodes if there is an odd number of backslashes.

    .. versionadded:: 0.2

    Parameters
    ----------
    m : regex match

    Returns
    -------
    c : str
        The unescaped character.

def _replace_fun_unescape(m):
    """ Decode single hex/unicode escapes found in regex matches.

    Supports single hex/unicode escapes of the form ``'\\xYY'``,
    ``'\\uYYYY'``, and ``'\\UYYYYYYYY'`` where Y is a hex digit. Only
    decodes if there is an odd number of backslashes.

    .. versionadded:: 0.2

    Parameters
    ----------
    m : regex match

    Returns
    -------
    c : str
        The unescaped character.

    """
    slsh = b'\\'.decode('ascii')
    s = m.group(0)
    count = s.count(slsh)
    if count % 2 == 0:
        return s
    else:
        if sys.hexversion >= 0x03000000:
            c = chr(int(s[(count + 1):], base=16))
        else:
            c = unichr(int(s[(count + 1):], base=16))
        return slsh * (count - 1) + c