import re


def clean_comments(line, pattern=None):
    """
    Clean commented lines or inline comments from a valid line
    Arguments:
    - line: string to be cleaned
    - pattern [optional]: regex compiled pattern, faster if an already compiled
                          pattern is sent
    Returns: string
    """
    if not pattern:
        pattern = re.compile(r'^([^#]*)[#;](.*)$')
    _match = re.match(pattern, line)
    if _match:
        return _match.group(1).strip()
    else:
        return line.strip()