import re


def domain(url):
    """Get domain from url.

    Domain must start with ``http://``, ``https://``
    or ``/``.

    Parameters
    ----------
    url: str
        URL to parse to extract the domain.

    Raises
    ------
    ValueError
        If the URL pattern is invalid.

    Examples
    --------
    >>> domain('https://example.com/test/page.html')
    'https://example.com/'
    >>> domain('http://example.com/test/page.html')
    'http://example.com/'
    >>> domain('/example.com/test/page.html')
    '/example.com/'


    """
    pattern = re.compile(r'^(https?:/)?(/[a-z0-9][a-z0-9-_.]*/)')
    res = pattern.match(url)
    if res:
        return res.group(2) if res.group(1) is None else ''.join(res.groups())

    raise ValueError(f'Invalid URL pattern: `{url}`.')