To remove specific words from a string in Python, use re.sub() with word boundaries so only whole words go, then tidy the spaces. Plain replace() works too, but it also cuts the word out of longer words:
import re
re.sub(r"\bsale\b", "", "Big sale on sales tables").split() # ['Big', 'on', 'sales', 'tables']
In this tutorial, we’ll compare four ways to do it, and I ran every script on Python 3.12.5 and pandas 3.0.6. Save each one as a .py file, open Command Prompt in that folder and run python file_name.py.
Remove a word with str.replace() and watch for partial matches
replace(old, "") deletes every occurrence of the text, wherever it sits. That’s fine for a unique word, but short words hide inside others:
text = "This listing is for a condo in Austin and it is pet friendly."
print(text.replace("is", "")) # also hits "This" and "listing"
print(text.replace(" is", "")) # safer here, still not bulletproof
print(text.replace(" is", "", 1)) # only the first match
Output:
Th lting for a condo in Austin and it pet friendly.
This listing for a condo in Austin and it pet friendly.
This listing for a condo in Austin and it is pet friendly.

"is" turns This into Th and listing into lting; adding the leading space avoids that.The optional third argument limits how many matches change. If you’re removing arbitrary text rather than words, my guide on removing a substring from a string in Python covers slicing and the other options.
How do I remove only whole words from a string?
Wrap the words in \b, the regex word boundary, so free can’t match inside Freestyle. re.escape() keeps characters like . or $ literal, and re.IGNORECASE catches any capitalization:
import re
subject = "URGENT: Act now for your free upgrade on Freestyle plans in Austin"
banned = ["urgent", "free", "act now"]
pattern = r"\b(?:" + "|".join(map(re.escape, banned)) + r")\b"
cleaned = re.sub(pattern, "", subject, flags=re.IGNORECASE)
print(repr(cleaned))
cleaned = re.sub(r"\s{2,}", " ", cleaned).strip(" :") # tidy the gaps
print(repr(cleaned))
Output:
': for your upgrade on Freestyle plans in Austin'
'for your upgrade on Freestyle plans in Austin'

Removing words always leaves extra spaces, so you’ll want the second pass. New to patterns? Start with regular expressions in Python, and see removing spaces from a string for more cleanup tricks.
Remove stopwords from a string with split() and join()
Stopwords are filler words like the, and or for. You split the text into words and keep the ones that aren’t in a set, with no regex needed. The catch is punctuation glued to a word:
import string
stop_words = {"the", "a", "an", "and", "of", "in", "to", "with"}
text = "Seattle has lots of cafes to work in. Pick one with fast Wi-Fi and a quiet corner."
naive = [w for w in text.split() if w.lower() not in stop_words]
print(" ".join(naive))
kept = [w for w in text.split()
if w.strip(string.punctuation).lower() not in stop_words]
print(" ".join(kept))
Output:
Seattle has lots cafes work in. Pick one fast Wi-Fi quiet corner.
Seattle has lots cafes work Pick one fast Wi-Fi quiet corner.

in. because the period sticks to it; stripping punctuation before the check removes it too.A set makes each lookup quick even with hundreds of stopwords. For more on the split step, see splitting a sentence into a list of words, or strip it all first with removing punctuation from strings.
Remove words from a pandas column
For a whole column, Series.str.replace() takes the same pattern. Pass regex=True and case=False, then rejoin the words to squeeze the spaces:
import pandas as pd
products = pd.Series([
"NEW Wireless Mouse - Sale",
"Laptop Stand (sale) new arrival",
"USB-C Hub Renewed",
])
pattern = r"\b(?:new|sale)\b"
clean = (products.str.replace(pattern, "", regex=True, case=False)
.str.replace(r"[()]|\s-\s", " ", regex=True)
.str.split().str.join(" "))
print(clean.to_string())
Output:
0 Wireless Mouse
1 Laptop Stand arrival
2 USB-C Hub Renewed

NEW and sale are gone in any case, while Renewed keeps its letters thanks to the word boundary.Need to know whether a word is there before you touch it? Use the checks in checking if a Python string contains a substring.
Word-removal methods compared
| Method | Whole words only | Best for |
|---|---|---|
s.replace(w, "") | No | Unique words, quick fixes |
re.sub(r"\bw\b", "", s) | Yes | Lists of words, any case |
split() + set + join() | Yes | Stopwords, long word lists |
Series.str.replace(..., regex=True) | Yes | pandas columns |
Keep going with these string cleanups:
- Remove prefixes from strings in Python
- Remove newlines from a string
- Count words in a file with Python
- Slice a string in Python
Frequently asked questions
How do I remove a word from a string in Python?
Use re.sub(r"\bword\b", "", text) for whole words, or text.replace("word", "") when partial matches can’t happen.
How do I remove multiple words at once?
Join them into one pattern: r"\b(?:" + "|".join(map(re.escape, words)) + r")\b", then call re.sub() once.
How do I remove a word without matching it inside other words?
Use the \b word boundary in a regex, or split the string and compare whole words.
How do I make word removal case-insensitive?
Pass flags=re.IGNORECASE to re.sub(), or case=False in pandas.
How do I get rid of double spaces after removing words?
Use " ".join(text.split()) or re.sub(r"\s{2,}", " ", text).strip().
Where is re.sub() documented?
See re.sub() in the Python docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn