There is no simple built-in string function that does what you're looking for, but you could use the more powerful regular expressions:

import re
[m.start() for m in re.finditer('test', 'test test test test')]
#[0, 5, 10, 15]

If you want to find overlapping matches, lookahead will do that:

[m.start() for m in re.finditer('(?=tt)', 'ttt')]
#[0, 1]

If you want a reverse find-all without overlaps, you can combine positive and negative lookahead into an expression like this:

search = 'tt'
[m.start() for m in re.finditer('(?=%s)(?!.{1,%d}%s)' % (search, len(search)-1, search), 'ttt')]
#[1]

re.finditer returns a generator, so you could change the [] in the above to () to get a generator instead of a list which will be more efficient if you're only iterating through the results once.

Answer from moinudin on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › re-findall-in-python
re.findall() in Python - GeeksforGeeks
July 23, 2025 - re.findall() method in Python helps us find all pattern occurrences in a string. It's like searching through a sentence to find every word that matches a specific rule.
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations — Python 3.14.7 ...
4 days ago - findall() matches all occurrences of a pattern, not just the first one as search() does.
🌐
Python Tutorial
pythontutorial.net › home › python regex › python regex findall()
Python Regex findall() Function By Practical Examples
December 10, 2021 - re.findall(pattern, string, flags=0)Code language: Python (python) ... The findall() function scans the string from left to right and finds all the matches of the pattern in the string.
🌐
ScrapeOps
scrapeops.io › home › python web scraping playbook › python beautifulsoup findall
How To Use BeautifulSoup's find_all() Method | ScrapeOps
November 3, 2022 - Simply add the regex query into the .find_all() method. For example, here we are using the .find_all() method with a regex expression to find all tags that start with the letter b:
Find elsewhere
🌐
ScraperAPI
scraperapi.com › home › blog › beautifulsoup’s find and find_all method: guide with example
BeautifulSoup's Find and Find_All Method: Guide with Example
March 18, 2026 - Learn how to use BeautifulSoup’s find() and find_all() methods to parse and extract web data from HTML and XML documents with Python. Easy web scraping guide.
🌐
Google
developers.google.com › google for education › python › python regular expressions
Python Regular Expressions | Python Education | Google for Developers
The re.findall(pat, str) function finds all matches of a pattern in a string and returns them as a list of strings or tuples, depending on whether the pattern contains capturing groups.
🌐
Medium
medium.com › @spaw.co › beautifulsoup-find-all-421385b341d4
Mastering BeautifulSoup’s find_all() Method for Web Scraping
May 3, 2024 - Among the various tools available for web scraping in Python, BeautifulSoup stands out for its ease of use and flexibility. This article delves into the find_all() method of BeautifulSoup, a critical function for extracting data from HTML and ...
🌐
W3Schools
w3schools.com › python › ref_string_find.asp
Python String find() Method
Python Examples Python Compiler ... Python Study Plan Python Interview Q&A Python Training ... The find() method finds the first occurrence of the specified value....
🌐
PYnative
pynative.com › home › python › regex › python regex find all matches using findall() and finditer()
Python Regex Find All Matches using findall() and finditer()
July 27, 2021 - Find all matches to the regular expression in Python using findall() and finditer(). Scans the regex pattern and returns all the matches that were found
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-can-i-find-all-matches-to-a-regular-expression-in-python
How Can I Find All Matches to a Regular Expression in Python? - GeeksforGeeks
July 23, 2025 - This function returns a list of all non-overlapping matches of the pattern in the string. The re.findall() function takes two main arguments. The first is the regex pattern you want to search for and the string where you want to perform the search.
🌐
LabEx
labex.io › tutorials › python-how-to-use-re-findall-in-python-to-find-all-matching-substrings-415132
How to use re.findall() in Python to find all matching substrings | LabEx
In the basic_findall.py file, write the following code: import re ## Sample text text = "Python is amazing. Python is versatile.
🌐
Bright Data
brightdata.com › blog › web-data › find-all-beautiful-soup
Find and Find_All in BeautifulSoup: A Complete 2026 Guide
September 16, 2025 - Learn how to use BeautifulSoup’s find() and find_all() methods to efficiently scrape web data by class, ID, text, and attributes in Python.
🌐
Medium
medium.com › @philipnirushan25 › understanding-the-difference-between-find-and-find-all-in-beautifulsoup-python-76bd0c25cec9
Understanding the Difference Between find() and find_all() in BeautifulSoup — Python | by Philip Nirushan | Medium
May 3, 2023 - Note that we passed the tag name ‘p’ and the attribute class_ (with an underscore to avoid conflict with Python’s reserved keyword) to find() to specify the criteria for the element we want to extract. Since find() stops after finding the first match, it returns a single element. ... Now, let’s use find_all() to extract all paragraph elements with the class “paragraph” from the same HTML snippet:
🌐
Python for Network Engineers
pyneng.readthedocs.io › en › latest › book › 15_module_re › findall.html
Findall function - Python for network engineers
Python 2.7 and Python 3.6 distinctions ... / Dark / Auto color theme · Toggle table of contents sidebar · Function findall: is used to search for all non-overlapping matches in string ·...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-all-occurrences-of-substring-in-string
Python - All occurrences of substring in string - GeeksforGeeks
July 12, 2025 - Using str.find() in a loop allows to find all occurrences of a substring by repeatedly searching for the next match starting from the last found index. The loop continues until no more matches are found (when find() returns -1). Python ·