如何在 Python 中用空字符串替换反斜杠后跟 2 个字母?

How to replace backslash followed by 2 letters with empty string in Python?

以下是测试字符串,我们需要将'\xa'替换为''

'FF 6 VRV AVENUE SUBRAMANIYAM PALAYAM PinCode:-\xa0641034'

我在 python 中使用了以下一组行来执行 objective 但没有用

new_str = str.replace(r'\xa', '')

但输出相同

'FF 6 VRV AVENUE SUBRAMANIYAM PALAYAM PinCode:-\xa0641034'

我认为您正在尝试替换 unicode 字符 '\xa0' -

s = 'FF 6 VRV AVENUE SUBRAMANIYAM PALAYAM PinCode:-\xa0641034' 
s = s.replace('\xa0', '') 
print(s)
#'FF 6 VRV AVENUE SUBRAMANIYAM PALAYAM PinCode:-641034'