Skip to content

Instantly share code, notes, and snippets.

@rz6agx
Created June 3, 2022 14:21
Show Gist options
  • Select an option

  • Save rz6agx/dcec401e8397a0b3875d0019afd540fe to your computer and use it in GitHub Desktop.

Select an option

Save rz6agx/dcec401e8397a0b3875d0019afd540fe to your computer and use it in GitHub Desktop.

Как из строки удалить конкретное слово?

Как удалить слово из текста, не затрагивая похожие слова с поисковым? например из фразы удалить 'some', но не затрагивая 'sometimes'?

import re
text = 'sometimes i want delete some from this text some'
string = re.sub(r'\ssome$|some\s', '', text)
print(string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment