lone = re.compile(
    '(?x)            # verbose expression (allows comments)\n    (                    \n    [\ud800-\udbff]      \n    (?![\udc00-\udfff])  \n    )                    \n    |                    \n    (                    \n    (?<![\ud800-\udbff]) \n    [\udc00-\udfff]      \n    )                    \n    '
    )
u = 'abc\ud834\ud82a\udfcdxyz'
print(repr(u))
b = lone.sub('\ufffd', u).encode('utf8')
print(repr(b))
print(repr(b.decode('utf8')))
обнаружить/удалить непарный суррогатный символ в Python 2 + GTK