Search code examples
pythontextpreprocessor

how to remove specific parts of string in python


I tried to remove specific words have same pattern that is specific same word next to.

doc = ["super man good weather", "bet man nice car", "iron man awesome soup"]

I want to remove 'super man', 'bet man', 'iron man' . these strings have same word 'man' and I want to remove the word in front of the same word 'man' at the same time.

I tried this but, failed.

for string in doc:
    prep = re.sub('.* man =', '', string)

Solution

  • Try this.. SHould work using re

    [re.sub('[a-zA-Z]+\s{1}man', '', txt).strip() for txt in doc]