end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

re.sub() & chr() for pythn で unicodeポイントの半角カナを文字へ変換

以下の通りかと思います

import re

def main():
    org_str    = r"\U+FF8A\U+FF72" # 「ハイ」の半角カナ
    # c.f. https://pystyle.info/python-convert-zenkaku-to-hankaku/
    re_pattern = r'(\\U\+)(FF[6-9][0-9A-F])'

    # c.f. https://note.nkmk.me/python-str-replace-translate-re-sub/#resub-resubn
    re_han_kana = re.compile(re_pattern)
    re_result = re_han_kana.sub(conv_re_sub, org_str)
    print( re_result )
    
def conv_re_sub(match_obj):
    tmp_str_2 = match_obj.group(2)
    # unicode code pointを文字へ
    return chr( int("0x"+tmp_str_2,16) )
    
if __name__ == '__main__':
    main()