import re


def re_find(s, r, pos=0, endpos=9223372036854775807):
    """
    Returns the match of the first occurrence of the regular expression
    `r` in string (or byte-sequence) `s`. This is essentially a wrapper
    for `re.finditer()` to avoid a try-catch StopIteration block.
    If `r` cannot be found, `None` will be returned.
    """
    if isinstance(r, (str, bytes)):
        if (pos, endpos) != (0, 9223372036854775807):
            rx = re.compile(r)
        else:
            try:
                m = next(re.finditer(r, s))
                return m
            except StopIteration:
                return None
    elif r:
        try:
            m = next(r.finditer(s, pos, endpos))
            return m
        except StopIteration:
            return None