import re
import time


def retry_on_exception(
    func, exception_regex: str, max_retries: int = 3, sleep_time: float = 5.0
):
    """Retry a function call if it raises an exception matching a regex."""
    counter = 0
    while True:
        try:
            return func()
        except Exception as e:
            if not re.search(exception_regex, str(e)):
                raise
            if counter >= max_retries:
                raise
            counter += 1
            time.sleep(sleep_time)