Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.findall solution in Clear category for Count Substring Occurrences by Olpag
import re
def count_occurrences(main_str: str, sub_str: str) -> int:
pattern = f'(?=({sub_str}))'
return len(re.findall(pattern, main_str, flags=re.I))
Nov. 8, 2023