from typing import Optional
from typing import Tuple
import re


def find_github_owner_repo(url: Optional[str]) -> Tuple[Optional[str], Optional[str]]:
    """Find the owner's name and repository name from the URL representing the GitHub
    repository.

    Parameters
    ----------
    url : Optional[str]
        Any string (expect it to be a URL).

    Returns
    -------
    owner : str or None
        Owner's name, or None if not found.
    repo : str or None
        Repository name, or None if not found.

    Examples
    --------
    >>> owner, repo = find_github_owner_repo("https://github.com/poyo46/lilili.git#foo")
    >>> assert owner == "poyo46"
    >>> assert repo == "lilili"

    >>> owner, repo = find_github_owner_repo("https://www.example.com")
    >>> assert owner is None
    >>> assert repo is None
    """
    if url is None:
        return None, None
    m = re.match(r"[^:/]+://github.com/(?P<owner>[^/]+)/(?P<repo>[^/#]+)", url)
    if m is None:
        return None, None
    repo = m.group("repo")
    if repo.endswith(".git"):
        repo = repo[:-4]
    return m.group("owner"), repo