Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Count Substring Occurrences by catloverss
def count_occurrences(main_str: str, sub_str: str) -> int:
main_str = main_str.lower()
sub_str = sub_str.lower()
count = start = 0
while True:
start = main_str.find(sub_str, start)
if start == -1:
break
count += 1
start += 1 # Move by 1 to allow overlapping matches
return count
Dec. 5, 2025
Comments: