如何使用python从字符串中删除确切的单词?

时间:2019-02-19 13:26:15

标签: python regex

input_data = "Test=60242444 Akshay Godase. REFREPLICATION553532 OBD:SATARA PUNE.NUM: 6252644M 55"

如何使用python从上述字符串中删除确切的单词?

我想从字符串中删除REFREPLICATION553532

如何从字符串中删除?

2 个答案:

答案 0 :(得分:1)

简单的字符串replace可以做到:)

>>> input_data = "Test=60242444 Akshay Godase. REFREPLICATION553532 OBD:SATARA PUNE.NUM: 6252644M 55"
>>> x = 'REFREPLICATION553532'
>>> replaced_string = input_data.replace(x, '')
>>> replaced_string
'Test=60242444 Akshay Godase.  OBD:SATARA PUNE.NUM: 6252644M 55'

答案 1 :(得分:0)


input_data = "Test=60242444 Akshay Godase. \
REFREPLICATION553532 OBD:SATARA PUNE.NUM: 6252644M 55"

input_data = str.replace(input_data, 'REFREPLICATION553532', '')