techwreck
techwreck

Reputation: 53

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

Following is the test string and we need to replace the '\xa' with ''

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

i was using the following set of lines in python to do the objective but to no use

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

but the output is same

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

Upvotes: 0

Views: 42

Answers (1)

Mortz
Mortz

Reputation: 4879

I think you are trying to replace the unicode character '\xa0' -

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

Upvotes: 1

Related Questions