One option is just to use the regex | character to try to match each of the substrings in the words in your Series s (still using str.contains).

You can construct the regex by joining the words in searchfor with |:

>>> searchfor = ['og', 'at']
>>> s[s.str.contains('|'.join(searchfor))]
0    cat
1    hat
2    dog
3    fog
dtype: object

As @AndyHayden noted in the comments below, take care if your substrings have special characters such as $ and ^ which you want to match literally. These characters have specific meanings in the context of regular expressions and will affect the matching.

You can make your list of substrings safer by escaping non-alphanumeric characters with re.escape:

>>> import re
>>> matches = ['$money', 'x^y']
>>> safe_matches = [re.escape(m) for m in matches]
>>> safe_matches
['\\$money', 'x\\^y']

The strings with in this new list will match each character literally when used with str.contains.

Answer from Alex Riley on Stack Overflow
🌐
PHP
php.net › manual › en › function.str-contains.php
PHP: str_contains - Manual
A couple of functions for checking if a string contains any of the strings in an array, or all of the strings in an array: <?php function str_contains_any(string $haystack, array $needles): bool { return array_reduce($needles, fn($a, $n) => $a || str_contains($haystack, $n), false); } function str_contains_all(string $haystack, array $needles): bool { return array_reduce($needles, fn($a, $n) => $a && str_contains($haystack, $n), true); } ?> str_contains_all() will return true if $needles is an empty array.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.contains.html
pandas.Series.str.contains — pandas 3.0.3 documentation
If False, treats the pat as a literal string. ... A Series or Index of boolean values indicating whether the given pattern is contained within the string of each element of the Series or Index.
Discussions

python - How to test if a string contains one of the substrings in a list, in pandas? - Stack Overflow
The strings with in this new list will match each character literally when used with str.contains. ... Sign up to request clarification or add additional context in comments. More on stackoverflow.com
🌐 stackoverflow.com
python - How to use str.contains() with multiple expressions in pandas dataframes - Stack Overflow
I'm wondering if there is a more efficient way to use the str.contains() function in Pandas, to search for two partial strings at once. I want to search a given column in a dataframe for data that contains either "nt" or "nv". More on stackoverflow.com
🌐 stackoverflow.com
python - pandas dataframe str.contains() AND operation - Stack Overflow
I'd like to grab strings that contains 10-20 different words (grape, watermelon, berry, orange, ..., etc.) More on stackoverflow.com
🌐 stackoverflow.com
How to use str.contains to get exact matches and not partial ones?
If you're looking for exact matches, str.contains may not be the function you should be using. The output looks correct to me in that all of the strings in the output do contain your keyword. More on reddit.com
🌐 r/learnpython
11
2
November 10, 2021
🌐
W3Schools
w3schools.com › java › ref_string_contains.asp
Java String contains() Method
The contains() method checks whether a string contains a sequence of characters. Returns true if the characters exist and false if not. ... The CharSequence interface is a readable sequence of char values, found in the java.lang package.
🌐
Medium
medium.com › @amit25173 › understanding-pandas-str-contains-ba3e6a7d30b3
Understanding pandas str.contains() | by Amit Yadav | Medium
March 6, 2025 - It checks each string in the Series to see if it contains 'an'. 'banana' and 'date' both have 'an', so they return True. The rest don’t, so they return False. It’s like asking, “Hey, does this word have the letters ‘an’ in it?” — and pandas answers with a simple True or False.
🌐
w3resource
w3resource.com › pandas › series › series-str-contains.php
Pandas Series: str.contains() function - w3resource
September 15, 2022 - The str.contains() function is used to test if pattern or regex is contained within a string of a Series or Index.
🌐
Programiz
programiz.com › python-programming › pandas › methods › str-contains
Pandas str.contains() (With Examples)
Then, we used the str.contains() method to check which elements in the Series contain the substring a. The result is a Series of Boolean values (True or False), indicating whether each element in data contains a.
Find elsewhere
🌐
Polars
docs.pola.rs › api › python › dev › reference › expressions › api › polars.Expr.str.contains.html
polars.Expr.str.contains — Polars documentation
>>> df = pl.DataFrame({"txt": ["Crab", "cat and dog", "rab$bit", None]}) >>> df.select( ... pl.col("txt"), ... pl.col("txt").str.contains("cat|bit").alias("regex"), ... pl.col("txt").str.contains("rab$", literal=True).alias("literal"), ...
🌐
Codecademy
codecademy.com › docs › php › string functions › str_contains()
PHP | String Functions | str_contains() | Codecademy
July 1, 2023 - Returns a boolean indicating if the specified string contains the substring provided.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-series-str-contains
Pandas Series.str.contains() - Python - GeeksforGeeks
January 13, 2026 - The Series.str.contains() method is used to check whether each string value in a Pandas Series contains a given substring or pattern.
🌐
PHP.Watch
php.watch › versions › 8.0 › str_contains
New `str_contains` function - PHP 8.0 • PHP.Watch
Most notably, Laravel offers a helper function str_contains(), but this function accepts an array of needles for the second parameter as well, which is not compatible with PHP core implementation. If you search for an empty needle (""), PHP will always return true. To quote Nikita: As of PHP 8, behavior of '' in string search functions is well defined, and we consider '' to occur at every position in the string, including one past the end. As such, both of these will (or ...
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › Series › str › contains
Python Pandas Series str contains() - Check Substring Presence | Vultr Docs
December 5, 2024 - Here, str.contains() analyzes the series to find any occurrence of 'a' or 'e'. The | character in the regular expression denotes a logical OR, so any string containing either character is flagged as True.
🌐
MathWorks
mathworks.com › simulink › modeling › configure signals, states, and parameters › data types
String Contains - Determine if string contains, starts with, or ends with pattern - Simulink
When Function is set to Contains, the block determines if the string contains a specified pattern. When Function is set to Starts with, the block determines if the string starts with a specified pattern. When Function is set to Ends with, the block determines if the string ends with a specified ...
🌐
Data.world
docs.data.world › documentation › sql › reference › functions › str_contains.html
STR_CONTAINS | SQL Tutorial Documentation on data.world
September 30, 2025 - The string function for checking if a string contains a substring. Returns true if the string contains the substring, and false if it does not.
🌐
Reddit
reddit.com › r/learnpython › how to use str.contains to get exact matches and not partial ones?
r/learnpython on Reddit: How to use str.contains to get exact matches and not partial ones?
November 10, 2021 -

Hi, I don't get why when I use str.contains to get exact matches from a list of keywords, the output still contains partial matches. Here is an extract of what I have (I'm only including one keyword in the list for the example):

keyword= ['SE.TER.ENRL']

subset = df[df['Code'].str.contains('|'.join(keyword), case=False, na=False)]

Output: ['SE.TER.ENRL' 'SE.TER.ENRL.FE' 'SE.TER.ENRL.FE.ZS']

Does anyone know how to get around this?

Thanks!

🌐
RDocumentation
rdocumentation.org › packages › sjmisc › versions › 2.8.11 › topics › str_contains
str_contains Check if string contains pattern
str_contains("hello", "hel") str_contains("hello", "hal") str_contains("hello", "Hel") str_contains("hello", "Hel", ignore.case = TRUE) # which patterns are in "abc"? str_contains("abc", c("a", "b", "e")) # is pattern in any element of 'x'? str_contains(c("def", "abc", "xyz"), "abc") # is "abcde" in any element of 'x'? str_contains(c("def", "abc", "xyz"), "abcde") # no... # is "abc" in any of pattern? str_contains("abc", c("defg", "abcde", "xyz12"), switch = TRUE) str_contains(c("def", "abcde", "xyz"), c("abc", "123")) # any pattern in "abc"? str_contains("abc", c("a", "b", "e"), logic = "or") # all patterns in "abc"?
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-str_contains-function
PHP str_contains() Function - GeeksforGeeks
September 9, 2021 - The str_contains() function is very similar to strpos() function. It always returns a boolean value. It will return TRUE in case of checking for the substring as empty. It is case-sensitive. This function is binary-safe. It is only supported on PHP 8 or higher versions.
🌐
Nabilhassen
nabilhassen.com › search-for-a-string-inside-another-string-in-php
PHP: Check if a string contains a substring - Nabil Hassen
November 13, 2025 - str_contains() is the clearest and most modern solution for checking if string contains substring in PHP 8 and newer. Use strpos() or stripos() when you need the match index or compatibility with older PHP versions.