import re


def find_url_matches(user_string):
    """Finds urls in a string

    returns a list of dictionaries with keys as follows
        matches[0]['protocol'] #protocol of url (http:// or https://)
        matches[0]['domain'] #domain of url (eg. sub.google.com)
        matches[0]['match']  #the found url (eg. http://google.com/asd?parm=3)
        matches[0]['']  #tuple of start and end (eg. (0, 18))

    :param user_string: sanitized input to check for urls

    """

    # unit tests
    # https://regex101.com/r/RoaTIC/4
    # ftp & ip & unicode fail for now.
    # & the classic (https://google.com/thing/) fails of course

    regex = re.compile(
        r'(https?:\/\/)'  # [1] protcol https:// || http://
        r'(www\.)?'       # [2] www. or nothing
        r'([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b)'  # [3] domain
        r'([/:][-a-zA-Z0-9@:%_\+\-,\*.~#?!&//=\(\)]*)?',  # [4] trailing
        re.IGNORECASE)

    matches = re.finditer(regex, user_string)

    # consider urllib.parse.urlparse

    matches_output = []
    for index, match in enumerate(matches):

        matches_output.append({
            'match':    match.group(0),
            'protocol': match.group(1),
            'domain':   match.group(3),
            'path':        match.group(4),
            'span':        match.span()
        })

    if not matches_output:
        return None

    return matches_output